You are here

public function PanelizerWidget::formElement in Lightning Layout 8

File

src/Plugin/Field/FieldWidget/PanelizerWidget.php, line 19

Class

PanelizerWidget
A Panelizer field widget plugin that supports view mode descriptions.

Namespace

Drupal\lightning_layout\Plugin\Field\FieldWidget

Code

public function formElement(FieldItemListInterface $items, $delta, array $element, array &$form, FormStateInterface $form_state) {
  $element = parent::formElement($items, $delta, $element, $form, $form_state);
  foreach (Element::children($element) as $i) {
    $item =& $element[$i];

    // If the item is associated with a view mode, display the view mode
    // description if no description is set already.
    if ($item['view_mode']['#value'] && empty($item['default']['#description'])) {
      $view_mode = $items
        ->getEntity()
        ->getEntityTypeId() . '.' . $item['view_mode']['#value'];
      if ($view_mode = EntityViewMode::load($view_mode)) {
        $element[$i]['default']['#description'] = $view_mode
          ->getThirdPartySetting('lightning_core', 'description');
      }
    }
  }
  return $element;
}