Verified Commit 90534ace authored by Lee Rowlands's avatar Lee Rowlands
Browse files

Issue #3001313 by bnjmnm, tim.plunkett, bobbygryzynger, Cyberschorsch,...

Issue #3001313 by bnjmnm, tim.plunkett, bobbygryzynger, Cyberschorsch, yogeshmpawar, mikey en, hershy.k, borisson_: Field blocks in the layout builder do not have view mode suggestions
parent 81179a0b
Loading
Loading
Loading
Loading
+12 −0
Changes for core/modules/layout_builder/layout_builder.module: 12 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -405,3 +405,15 @@ function layout_builder_preprocess_language_content_settings_table(&$variables)
    }
  }
}

/**
 * Implements hook_theme_suggestions_HOOK_alter().
 */
function layout_builder_theme_suggestions_field_alter(&$suggestions, array $variables) {
  $element = $variables['element'];
  if (isset($element['#third_party_settings']['layout_builder']['view_mode'])) {
    // See system_theme_suggestions_field().
    $suggestions[] = 'field__' . $element['#entity_type'] . '__' . $element['#field_name'] . '__' . $element['#bundle'] . '__' . $element['#third_party_settings']['layout_builder']['view_mode'];
  }
  return $suggestions;
}
+1 −0
Changes for core/modules/layout_builder/src/LayoutEntityHelperTrait.php: 1 added line, 0 removed lines.
Original line number Diff line number Diff line
@@ -109,6 +109,7 @@ protected function getSectionStorageForEntity(EntityInterface $entity) {
    $view_mode = 'full';
    if ($entity instanceof LayoutEntityDisplayInterface) {
      $contexts['display'] = EntityContext::fromEntity($entity);
      $contexts['view_mode'] = new Context(new ContextDefinition('string'), $entity->getMode());
    }
    else {
      $contexts['entity'] = EntityContext::fromEntity($entity);
+1 −0
Changes for core/modules/layout_builder/src/Plugin/Block/FieldBlock.php: 1 added line, 0 removed lines.
Original line number Diff line number Diff line
@@ -156,6 +156,7 @@ protected function getEntity() {
   */
  public function build() {
    $display_settings = $this->getConfiguration()['formatter'];
    $display_settings['third_party_settings']['layout_builder']['view_mode'] = $this->getContextValue('view_mode');
    $entity = $this->getEntity();
    try {
      $build = $entity->get($this->fieldName)->view($display_settings);
+2 −0
Changes for core/modules/layout_builder/src/Plugin/Derivative/FieldBlockDeriver.php: 2 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -9,6 +9,7 @@
use Drupal\Core\Field\FieldConfigInterface;
use Drupal\Core\Field\FieldTypePluginManagerInterface;
use Drupal\Core\Field\FormatterPluginManager;
use Drupal\Core\Plugin\Context\ContextDefinition;
use Drupal\Core\Plugin\Context\EntityContextDefinition;
use Drupal\Core\Plugin\Discovery\ContainerDeriverInterface;
use Drupal\Core\StringTranslation\StringTranslationTrait;
@@ -123,6 +124,7 @@ public function getDerivativeDefinitions($base_plugin_definition) {
          $context_definition->addConstraint('Bundle', [$bundle]);
          $derivative['context_definitions'] = [
            'entity' => $context_definition,
            'view_mode' => new ContextDefinition('string'),
          ];

          $derivative_id = $entity_type_id . PluginBase::DERIVATIVE_SEPARATOR . $bundle . PluginBase::DERIVATIVE_SEPARATOR . $field_name;
+13 −0
Changes for core/modules/layout_builder/src/Plugin/SectionStorage/DefaultsSectionStorage.php: 13 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -2,6 +2,7 @@

namespace Drupal\layout_builder\Plugin\SectionStorage;

use Drupal\Component\Plugin\Context\ContextInterface as ComponentContextInterface;
use Drupal\Component\Utility\NestedArray;
use Drupal\Core\Access\AccessResult;
use Drupal\Core\Cache\RefinableCacheableDependencyInterface;
@@ -33,6 +34,7 @@
 *   weight = 20,
 *   context_definitions = {
 *     "display" = @ContextDefinition("entity:entity_view_display"),
 *     "view_mode" = @ContextDefinition("string", default_value = "default"),
 *   },
 * )
 *
@@ -432,4 +434,15 @@ public function isApplicable(RefinableCacheableDependencyInterface $cacheability
    return $this->isLayoutBuilderEnabled();
  }

  /**
   * {@inheritdoc}
   */
  public function setContext($name, ComponentContextInterface $context) {
    // Set the view mode context based on the display context.
    if ($name === 'display') {
      $this->setContextValue('view_mode', $context->getContextValue()->getMode());
    }
    parent::setContext($name, $context);
  }

}
Loading