Skip to content

Instantly share code, notes, and snippets.

@g3r4
Created February 8, 2018 22:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save g3r4/6a4b0779ba72ae256ad5a38d68ed362e to your computer and use it in GitHub Desktop.
Save g3r4/6a4b0779ba72ae256ad5a38d68ed362e to your computer and use it in GitHub Desktop.
Hero image patch for Open Social
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