You are here

public function MediaForm::getEntityData in GridStack 8.2

Return available entity data.

File

src/Plugin/gridstack/stylizer/MediaForm.php, line 161

Class

MediaForm
Provides the media form for Layout Builder integration.

Namespace

Drupal\gridstack\Plugin\gridstack\stylizer

Code

public function getEntityData($entity_form) {
  $extras = [];
  $id = NULL;
  $bundle = NULL;
  $entity = NULL;
  $target = NULL;
  $mode = NULL;

  /* @var \Drupal\layout_builder\Form\ConfigureSectionForm $storage (Layout Builder) */
  if (method_exists($entity_form, 'getSectionStorage') && ($storage = $entity_form
    ->getSectionStorage())) {
    $contexts = $storage
      ->getContextValues();
    if (isset($contexts['entity']) && ($entity = $contexts['entity'])) {
      $id = $entity
        ->id();
      $bundle = $entity
        ->bundle();
      $target = $entity
        ->getEntityTypeId();
      $mode = $contexts['view_mode'];
      $this
        ->setEntity($entity);
    }
    elseif (isset($contexts['display']) && ($display = $contexts['display'])) {
      $id = $display
        ->id();
      $bundle = $display
        ->getTargetBundle();
      $target = $display
        ->getTargetEntityTypeId();
      $mode = $contexts['view_mode'];
    }
  }
  elseif (method_exists($entity_form, 'getEntity') && ($entity = $entity_form
    ->getEntity())) {
    $id = $entity
      ->id();
    $bundle = $entity
      ->getTargetBundle();
    $target = $entity
      ->getTargetEntityTypeId();
    $mode = $entity
      ->getMode();
    $this
      ->setEntity($entity);
  }
  if ($bundle) {
    $extras = [
      'entity' => $entity,
      'bundle' => $bundle,
      'entity_id' => $id,
      'entity_type_id' => $target,
      'view_mode' => $mode,
    ];
    $this->targetEntityType = $target;
    $this->bundle = $bundle;
  }
  return $extras;
}