getStorageId example


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

    // If the delta and the count are the same, it is either the end of the     // layout or an empty layout.     if ($delta === count($section_storage)) {
      if ($delta === 0) {
        $title = $this->t('Add section');
      }
      else {
        $title = $this->t('Add section <span class="visually-hidden">at end of layout</span>');
      }
    }
    
    // view_mode context with the value "default".     if (!isset($contexts['view_mode']) || $contexts['view_mode']->validate()->count() || !$contexts['view_mode']->getContextValue()) {
      $contexts['view_mode'] = new Context(new ContextDefinition('string'), 'default');
    }
    return $contexts;
  }

  /** * {@inheritdoc} */
  public function getTempstoreKey() {
    return $this->getStorageId();
  }

}
/** * Provides a title callback. * * @param \Drupal\layout_builder\SectionStorageInterface $section_storage * The section storage. * * @return string * The title for the layout page. */
  public function title(SectionStorageInterface $section_storage) {
    assert(Inspector::assertStringable($section_storage->label()), 'Section storage label is expected to be a string.');
    return $this->t('Edit layout for %label', ['%label' => $section_storage->label() ?? $section_storage->getStorageType() . ' ' . $section_storage->getStorageId()]);
  }

  /** * Renders the Layout UI. * * @param \Drupal\layout_builder\SectionStorageInterface $section_storage * The section storage. * * @return array * A render array. */
  
/** * {@inheritdoc} */
  public function getStorageId() {
    return $this->getContextValue('config_id');
  }

  /** * {@inheritdoc} */
  public function label() {
    return $this->getStorageId();
  }

  /** * Returns the name to be used to store in the config system. */
  protected function getConfigName() {
    return 'layout_builder_test.' . $this->getStorageType() . '.' . $this->getStorageId();
  }

  /** * {@inheritdoc} */
'#title' => [
          'icon' => $definition->getIcon(60, 80, 1, 3),
          'label' => [
            '#type' => 'container',
            '#children' => $definition->getLabel(),
          ],
        ],
        '#url' => Url::fromRoute(
          $layout instanceof PluginFormInterface ? 'layout_builder.configure_section' : 'layout_builder.add_section',
          [
            'section_storage_type' => $section_storage->getStorageType(),
            'section_storage' => $section_storage->getStorageId(),
            'delta' => $delta,
            'plugin_id' => $plugin_id,
          ]
        ),
      ];
      if ($this->isAjax()) {
        $item['#attributes']['class'][] = 'use-ajax';
        $item['#attributes']['data-dialog-type'][] = 'dialog';
        $item['#attributes']['data-dialog-renderer'][] = 'off_canvas';
      }
      $items[$plugin_id] = $item;
    }

  public function getCancelUrl() {
    return $this->sectionStorage->getLayoutBuilderUrl();
  }

  /** * {@inheritdoc} */
  public function buildForm(array $form, FormStateInterface $form_state, SectionStorageInterface $section_storage = NULL) {
    if (!$section_storage instanceof OverridesSectionStorageInterface) {
      throw new \InvalidArgumentException(sprintf('The section storage with type "%s" and ID "%s" does not provide overrides', $section_storage->getStorageType()$section_storage->getStorageId()));
    }

    $this->sectionStorage = $section_storage;
    // Mark this as an administrative page for JavaScript ("Back to site" link).     $form['#attached']['drupalSettings']['path']['currentPathIsAdmin'] = TRUE;
    return parent::buildForm($form$form_state);
  }

  /** * {@inheritdoc} */
  

  public function build(SectionStorageInterface $section_storage, int $delta$region) {
    if ($this->entityTypeManager->hasDefinition('block_content_type') && $types = $this->entityTypeManager->getStorage('block_content_type')->loadMultiple()) {
      if (count($types) === 1) {
        $type = reset($types);
        $plugin_id = 'inline_block:' . $type->id();
        if ($this->blockManager->hasDefinition($plugin_id)) {
          $url = Url::fromRoute('layout_builder.add_block', [
            'section_storage_type' => $section_storage->getStorageType(),
            'section_storage' => $section_storage->getStorageId(),
            'delta' => $delta,
            'region' => $region,
            'plugin_id' => $plugin_id,
          ]);
        }
      }
      else {
        $url = Url::fromRoute('layout_builder.choose_inline_block', [
          'section_storage_type' => $section_storage->getStorageType(),
          'section_storage' => $section_storage->getStorageId(),
          'delta' => $delta,
          

class LayoutTempstoreRepositoryTest extends UnitTestCase {

  /** * @covers ::get * @covers ::has */
  public function testGetEmptyTempstore() {
    $section_storage = $this->prophesize(SectionStorageInterface::class);
    $section_storage->getStorageType()->willReturn('my_storage_type');
    $section_storage->getStorageId()->willReturn('my_storage_id');

    $tempstore = $this->prophesize(SharedTempStore::class);
    $tempstore->get('my_storage_id')->shouldBeCalled();

    $tempstore_factory = $this->prophesize(SharedTempStoreFactory::class);
    $tempstore_factory->get('layout_builder.section_storage.my_storage_type')->willReturn($tempstore->reveal());

    $repository = new LayoutTempstoreRepository($tempstore_factory->reveal());

    $this->assertFalse($repository->has($section_storage->reveal()));

    

  public function getCancelUrl() {
    return $this->sectionStorage->getRedirectUrl();
  }

  /** * {@inheritdoc} */
  public function buildForm(array $form, FormStateInterface $form_state, SectionStorageInterface $section_storage = NULL) {
    if (!$section_storage instanceof DefaultsSectionStorageInterface) {
      throw new \InvalidArgumentException(sprintf('The section storage with type "%s" and ID "%s" does not provide defaults', $section_storage->getStorageType()$section_storage->getStorageId()));
    }

    $this->sectionStorage = $section_storage;
    // Mark this as an administrative page for JavaScript ("Back to site" link).     $form['#attached']['drupalSettings']['path']['currentPathIsAdmin'] = TRUE;
    return parent::buildForm($form$form_state);
  }

  /** * {@inheritdoc} */
  

  protected function getKey(SectionStorageInterface $section_storage) {
    if ($section_storage instanceof TempStoreIdentifierInterface) {
      return $section_storage->getTempstoreKey();
    }

    return $section_storage->getStorageId();
  }

}
Home | Imprint | This part of the site doesn't use cookies.