| Conditions | 9 |
| Paths | 48 |
| Total Lines | 64 |
| Code Lines | 33 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 46 | public function buildEntityEmbed(EntityInterface $entity, array $context = []) { |
||
| 47 | // Support the deprecated view-mode data attribute. |
||
| 48 | if (isset($context['data-view-mode']) && !isset($context['data-entity-embed-display']) && !isset($context['data-entity-embed-display-settings'])) { |
||
| 49 | $context['data-entity-embed-display'] = 'entity_reference:entity_reference_entity_view'; |
||
| 50 | $context['data-entity-embed-display-settings'] = ['view_mode' => &$context['data-view-mode']]; |
||
| 51 | } |
||
| 52 | |||
| 53 | // Merge in default attributes. |
||
| 54 | $context += [ |
||
| 55 | 'data-entity-type' => $entity->getEntityTypeId(), |
||
| 56 | 'data-entity-uuid' => $entity->uuid(), |
||
| 57 | 'data-entity-embed-display' => 'entity_reference:entity_reference_entity_view', |
||
| 58 | 'data-entity-embed-display-settings' => [], |
||
| 59 | ]; |
||
| 60 | |||
| 61 | // The default Entity Embed Display plugin has been deprecated by the |
||
| 62 | // rendered entity field formatter. |
||
| 63 | if ($context['data-entity-embed-display'] === 'default') { |
||
| 64 | $context['data-entity-embed-display'] = 'entity_reference:entity_reference_entity_view'; |
||
| 65 | } |
||
| 66 | |||
| 67 | // The caption text is double-encoded, so decode it here. |
||
| 68 | if (isset($context['data-caption'])) { |
||
| 69 | $context['data-caption'] = Html::decodeEntities($context['data-caption']); |
||
| 70 | } |
||
| 71 | |||
| 72 | // Allow modules to alter the entity prior to embed rendering. |
||
| 73 | $this->moduleHandler->alter(["{$context['data-entity-type']}_embed_context", 'entity_embed_context'], $context, $entity); |
||
| 74 | |||
| 75 | // Build and render the Entity Embed Display plugin, allowing modules to |
||
| 76 | // alter the result before rendering. |
||
| 77 | $build = [ |
||
| 78 | '#theme_wrappers' => ['entity_embed_container'], |
||
| 79 | '#attributes' => ['class' => ['embedded-entity']], |
||
| 80 | '#entity' => $entity, |
||
| 81 | '#context' => $context, |
||
| 82 | ]; |
||
| 83 | $build['entity'] = $this->buildEntityEmbedDisplayPlugin( |
||
| 84 | $entity, |
||
| 85 | $context['data-entity-embed-display'], |
||
| 86 | $context['data-entity-embed-display-settings'], |
||
| 87 | $context |
||
| 88 | ); |
||
| 89 | |||
| 90 | // Maintain data-align if it is there. |
||
| 91 | if (isset($context['data-align'])) { |
||
| 92 | $build['#attributes']['data-align'] = $context['data-align']; |
||
| 93 | } |
||
| 94 | elseif ((isset($context['class']))) { |
||
| 95 | $build['#attributes']['class'][] = $context['class']; |
||
| 96 | } |
||
| 97 | |||
| 98 | // Maintain data-caption if it is there. |
||
| 99 | if (isset($context['data-caption'])) { |
||
| 100 | $build['#attributes']['data-caption'] = $context['data-caption']; |
||
| 101 | } |
||
| 102 | |||
| 103 | // Make sure that access to the entity is respected. |
||
| 104 | $build['#access'] = $entity->access('view', NULL, TRUE); |
||
| 105 | |||
| 106 | // @todo Should this hook get invoked if $build is an empty array? |
||
| 107 | $this->moduleHandler->alter(["{$context['data-entity-type']}_embed", 'entity_embed'], $build, $entity, $context); |
||
| 108 | return $build; |
||
| 109 | } |
||
| 110 | |||
| 144 |