You are here

protected function MediaForm::getFieldData in GridStack 8.2

Returns available field media data.

3 calls to MediaForm::getFieldData()
MediaForm::getFieldDefinition in src/Plugin/gridstack/stylizer/MediaForm.php
Returns available field media definition.
MediaForm::getFieldSettings in src/Plugin/gridstack/stylizer/MediaForm.php
Returns available field media settings.
MediaForm::getLayoutFieldOptions in src/Plugin/gridstack/stylizer/MediaForm.php
Returns available field media for select options.

File

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

Class

MediaForm
Provides the media form for Layout Builder integration.

Namespace

Drupal\gridstack\Plugin\gridstack\stylizer

Code

protected function getFieldData($name = '', $key = '') {
  $field_definitions = $this
    ->getFieldDefinitions();
  if (empty($field_definitions)) {
    return [];
  }
  $options = $definitions = $output = [];
  foreach ($field_definitions as $field_definition) {
    if ($field_definition
      ->getType() != 'entity_reference') {
      continue;
    }
    $field_settings = $field_definition
      ->getSettings();
    $field_name = $field_definition
      ->getName();
    if ($field_settings['handler'] == 'default:media') {
      if ($field_definition
        ->getFieldStorageDefinition()
        ->getCardinality() !== FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED) {
        continue;
      }
      $options[$field_name] = $field_name;

      // @todo move it to getFieldSettings() based on selected field.
      $this
        ->setFieldSettings($field_settings['handler_settings']);
      $definitions[$field_name] = $key == 'settings' && $name == $field_name ? $field_settings['handler_settings'] : $field_definition;
    }
  }
  if ($definitions) {
    $definitions = $name ? $definitions[$name] : $definitions;
    $output = $key == 'options' ? $options : $definitions;
  }
  return $output;
}