You are here

public function TranslatableOverridesSectionStorage::getSectionListFromId in Layout Builder Asymmetric Translation 8

Derives the section list from the storage ID.

@internal This should only be called during section storage instantiation.

Parameters

string $id: The storage ID, see ::getStorageId().

Return value

\Drupal\layout_builder\SectionListInterface The section list.

Throws

\InvalidArgumentException Thrown if the ID is invalid.

Overrides OverridesSectionStorage::getSectionListFromId

Deprecated

in drupal:8.7.0 and is removed from drupal:9.0.0. The section list should be derived from context. See https://www.drupal.org/node/3016262.

File

src/Plugin/SectionStorage/TranslatableOverridesSectionStorage.php, line 13

Class

TranslatableOverridesSectionStorage

Namespace

Drupal\layout_builder_at\Plugin\SectionStorage

Code

public function getSectionListFromId($id) {
  if (strpos($id, '.') !== FALSE) {
    list($entity_type_id, $entity_id) = explode('.', $id, 2);
    $entity = $this->entityTypeManager
      ->getStorage($entity_type_id)
      ->load($entity_id);

    // Get translation from context.
    $entity = \Drupal::service('entity.repository')
      ->getTranslationFromContext($entity);
    if ($entity instanceof FieldableEntityInterface && $entity
      ->hasField(static::FIELD_NAME)) {
      return $entity
        ->get(static::FIELD_NAME);
    }
  }
  throw new \InvalidArgumentException(sprintf('The "%s" ID for the "%s" section storage type is invalid', $id, $this
    ->getStorageType()));
}