Created
February 8, 2018 22:24
-
-
Save g3r4/6a4b0779ba72ae256ad5a38d68ed362e to your computer and use it in GitHub Desktop.
Hero image patch for Open Social
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/modules/social_features/social_core/social_core.module b/modules/social_features/social_core/social_core.module | |
index 8e35646..e523b32 100644 | |
--- a/modules/social_features/social_core/social_core.module | |
+++ b/modules/social_features/social_core/social_core.module | |
@@ -94,11 +94,28 @@ function template_preprocess_page_hero_data(array &$variables) { | |
if (!empty($node->{$image_field}->entity)) { | |
$variables['hero_styled_image_url'] = ImageStyle::load('social_xx_large') | |
->buildUrl($node->{$image_field}->entity->getFileUri()); | |
+ } else { // If machine name too long or using another image field | |
+ $node_fields = $node->getFields(); | |
+ $image_fields = array_filter($node_fields, "findImageField"); | |
+ // Get the first image field of all the fields | |
+ $field = reset($image_fields); | |
+ if ($field != NULL){ | |
+ if ($field->getFieldDefinition()->get("field_type") == "image") { | |
+ if (!empty(($node->get($field->getName())->entity))) { | |
+ $variables['hero_styled_image_url'] = ImageStyle::load('social_xx_large') | |
+ ->buildUrl($node->get($field->getName())->entity->getFileUri()); | |
+ } | |
+ } | |
+ } | |
+ } | |
+ } | |
+ } | |
+ | |
+ function findImageField($field){ | |
+ if (strpos($field->getName(), 'image') !== false) { | |
+ return $field; | |
} | |
- | |
} | |
- | |
-} | |
/** | |
* Implements hook_form_FORM_ID_alter(). |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment