getLayout example

$target_entity_type = $this->entityTypeManager()->getDefinition($this->getTargetEntityTypeId());
    return new TranslatableMarkup('@bundle @label', ['@bundle' => $bundle_label, '@label' => $target_entity_type->getPluralLabel()]);
  }

  /** * {@inheritdoc} */
  public function calculateDependencies() {
    parent::calculateDependencies();

    foreach ($this->getSections() as $section) {
      $this->calculatePluginDependencies($section->getLayout());
      foreach ($section->getComponents() as $component) {
        $this->calculatePluginDependencies($component->getPlugin());
      }
    }

    return $this;
  }

  /** * {@inheritdoc} */
  
/** * Overrides \Drupal\Core\Entity\EntityDisplayBase::preSave(). */
  public function preSave(EntityStorageInterface $storage) {
    parent::preSave($storage);

    // Ensure the plugin configuration is updated. Once layouts are no longer     // stored as third party settings, this will be handled by the code in     // \Drupal\Core\Config\Entity\ConfigEntityBase::preSave() that handles     // \Drupal\Core\Entity\EntityWithPluginCollectionInterface.     if ($this->getLayoutId()) {
      $this->setLayout($this->getLayout());
    }
  }

  /** * {@inheritdoc} */
  public function ensureLayout($default_layout_id = 'layout_onecol') {
    if (!$this->getLayoutId()) {
      $this->setLayoutId($default_layout_id);
    }

    
// use the theme persister class to write the Shopware\Components\Form elements into the database         $this->persister->save($container$template);

        $this->eventManager->notify('Theme_Configurator_Theme_Config_Saved', [
            'theme' => $theme,
            'template' => $template,
            'container' => $container,
        ]);

        $this->removeUnused(
            $this->getLayout($template),
            $this->getElements($template),
            $container
        );

        $this->synchronizeSets($theme$template);

        $this->eventManager->notify('Theme_Configurator_Theme_Config_Synchronized', [
            'theme' => $theme,
            'template' => $template,
            'container' => $container,
        ]);
    }
$section = $this->getCurrentSection();

    if ($this->isUpdate) {
      if ($label = $section->getLayoutSettings()['label']) {
        $form['#title'] = $this->t('Configure @section', ['@section' => $label]);
      }
    }
    // Passing available contexts to the layout plugin here could result in an     // exception since the layout may not have a context mapping for a required     // context slot on creation.     $this->layout = $section->getLayout();

    $form_state->setTemporaryValue('gathered_contexts', $this->getPopulatedContexts($this->sectionStorage));
    $form['#tree'] = TRUE;
    $form['layout_settings'] = [];
    $subform_state = SubformState::createForSubform($form['layout_settings']$form$form_state);
    $form['layout_settings'] = $this->getPluginForm($this->layout)->buildConfigurationForm($form['layout_settings']$subform_state);

    $form['actions']['submit'] = [
      '#type' => 'submit',
      '#value' => $this->isUpdate ? $this->t('Update') : $this->t('Add section'),
      '#button_type' => 'primary',
    ];
if (!$template instanceof Template) {
            throw new ModelNotFoundException(Template::class$data['id']);
        }

        $shop = $this->getManager()->find(
            Shop::class,
            $this->Request()->getParam('shopId')
        );

        $data['hasConfigSet'] = $this->hasTemplateConfigSet($template);

        $data['configLayout'] = $this->container->get(Service::class)->getLayout(
            $template,
            $shop
        );

        $data['themeInfo'] = $this->getThemeInfo($template);

        return $this->get('events')->filter('Shopware_Theme_Detail_Loaded', $data[
            'shop' => $shop,
            'template' => $template,
        ]);
    }

    
/** * Overrides \Drupal\field_ui\Form\EntityDisplayFormBase::form(). */
  public function form(array $form, FormStateInterface $form_state) {
    $form = parent::form($form$form_state);

    $form['field_layouts'] = [
      '#type' => 'details',
      '#title' => $this->t('Layout settings'),
    ];

    $layout_plugin = $this->getLayout($this->getEntity()$form_state);

    $form['field_layouts']['field_layout'] = [
      '#type' => 'select',
      '#title' => $this->t('Select a layout'),
      '#options' => $this->layoutPluginManager->getLayoutOptions(),
      '#default_value' => $layout_plugin->getPluginId(),
      '#ajax' => [
        'callback' => '::settingsAjax',
        'wrapper' => 'field-layout-settings-wrapper',
        'trigger_as' => ['name' => 'field_layout_change'],
      ],
    ];

  public function toRenderArray(array $contexts = []$in_preview = FALSE) {
    $regions = [];
    foreach ($this->getComponents() as $component) {
      if ($output = $component->toRenderArray($contexts$in_preview)) {
        $regions[$component->getRegion()][$component->getUuid()] = $output;
      }
    }

    $layout = $this->getLayout($contexts);
    if ($layout instanceof PreviewAwarePluginInterface) {
      $layout->setInPreview($in_preview);
    }

    $build = $layout->build($regions);
    // If an entity was used to build the layout, store it on the build.     if (!Element::isEmpty($build) && isset($contexts['layout_builder.entity'])) {
      $build['#entity'] = $contexts['layout_builder.entity']->getContextValue();
    }
    return $build;
  }

  
$context_handler->applyContextMapping($layout->reveal()$contexts)->shouldBeCalled();
    }
    else {
      $context_handler->applyContextMapping($layout->reveal()$contexts)->shouldNotBeCalled();
    }

    $container = new ContainerBuilder();
    $container->set('plugin.manager.core.layout', $layout_plugin_manager->reveal());
    $container->set('context.handler', $context_handler->reveal());
    \Drupal::setContainer($container);

    $output = $this->section->getLayout($contexts);
    $this->assertSame($layout->reveal()$output);
  }

  /** * Provides test data for ::testGetLayout(). */
  public function providerTestGetLayout() {
    $data = [];
    $data['contexts'] = [['foo' => 'bar'], TRUE];
    $data['no contexts'] = [[], FALSE];
    return $data;
  }

  protected function buildAdministrativeSection(SectionStorageInterface $section_storage$delta) {
    $storage_type = $section_storage->getStorageType();
    $storage_id = $section_storage->getStorageId();
    $section = $section_storage->getSection($delta);

    $layout = $section->getLayout($this->getPopulatedContexts($section_storage));
    $layout_settings = $section->getLayoutSettings();
    $section_label = !empty($layout_settings['label']) ? $layout_settings['label'] : $this->t('Section @section', ['@section' => $delta + 1]);

    $build = $section->toRenderArray($this->getPopulatedContexts($section_storage), TRUE);
    $layout_definition = $layout->getPluginDefinition();

    $region_labels = $layout_definition->getRegionLabels();
    foreach ($layout_definition->getRegions() as $region => $info) {
      if (!empty($build[$region])) {
        foreach (Element::children($build[$region]) as $uuid) {
          $build[$region][$uuid]['#attributes']['class'][] = 'js-layout-builder-block';
          
'non_configurable_field' => [
        '#markup' => 'Non-configurable',
      ],
      'non_configurable_field_with_extra_field' => [
        '#markup' => 'Non-configurable with extra field',
      ],
    ];

    $display = $this->prophesize(EntityDisplayWithLayoutInterface::class);
    $display->getTargetEntityTypeId()->willReturn('the_entity_type_id');
    $display->getTargetBundle()->willReturn('the_entity_type_bundle');
    $display->getLayout()->willReturn($this->layoutPlugin);
    $display->getLayoutId()->willReturn('two_column');
    $display->getLayoutSettings()->willReturn([]);
    $display->getComponents()->willReturn([
      'test1' => [
        'region' => 'right',
      ],
      'test2' => [
        'region' => 'unknown_region',
      ],
      'non_configurable_field' => [
        'region' => 'left',
      ],
$this->sectionStorage = $section_storage;
    $this->delta = $delta;
    $this->uuid = $uuid;
    $this->region = $region;

    $form['#attributes']['data-layout-builder-target-highlight-id'] = $this->blockUpdateHighlightId($uuid);

    $sections = $section_storage->getSections();
    $contexts = $this->getPopulatedContexts($section_storage);
    $region_options = [];
    foreach ($sections as $section_delta => $section) {
      $layout = $section->getLayout($contexts);
      $layout_definition = $layout->getPluginDefinition();
      if (!($section_label = $section->getLayoutSettings()['label'])) {
        $section_label = $this->t('Section: @delta', ['@delta' => $section_delta + 1])->render();
      }
      foreach ($layout_definition->getRegions() as $region_name => $region_info) {
        // Group regions by section.         $region_options[$section_label]["$section_delta:$region_name"] = $this->t(
          '@section, Region: @region',
          ['@section' => $section_label, '@region' => $region_info['label']]
        );
      }
    }
        // top-level of $build into a region-specific section. Custom regions         // could be set by other code at run-time; these should be ignored.         // @todo Ideally the array structure would remain unchanged, see         // https://www.drupal.org/node/2846393.         if (isset($regions[$field['region']])) {
          $regions[$field['region']][$name] = $build[$name];
          unset($build[$name]);
        }
      }
      // Ensure this will not conflict with any existing array elements by       // prefixing with an underscore.       $build['_field_layout'] = $display->getLayout()->build($regions);
    }
  }

  /** * Applies the layout to an entity form. * * @param array $build * A renderable array representing the entity content or form. * @param \Drupal\field_layout\Display\EntityDisplayWithLayoutInterface $display * The entity display holding the display options configured for the entity * components. */
Home | Imprint | This part of the site doesn't use cookies.