You are here

public static function EntityReferenceLayoutRevisioned::fieldSettingsToConfigData in Entity Reference with Layout 8

Manipulate field data to be saved as configuration.

Overrides FieldItemBase::fieldSettingsToConfigData

File

src/Plugin/Field/FieldType/EntityReferenceLayoutRevisioned.php, line 96

Class

EntityReferenceLayoutRevisioned
Entity Reference Layout Revisioned field type.

Namespace

Drupal\entity_reference_layout\Plugin\Field\FieldType

Code

public static function fieldSettingsToConfigData(array $settings) {
  $settings = parent::fieldSettingsToConfigData($settings);
  $allowed_layouts = [];
  $selected_layouts = isset($settings['handler_settings']['allowed_layouts']) ? $settings['handler_settings']['allowed_layouts'] : [];
  $layout_groups = \Drupal::service('plugin.manager.core.layout')
    ->getLayoutOptions();
  foreach ($layout_groups as $group => $layouts) {
    foreach ($layouts as $name => $value) {
      if (!empty($selected_layouts[$group][$name])) {
        $allowed_layouts[$group][$name] = $value;
      }
    }
  }
  $settings['handler_settings']['allowed_layouts'] = $allowed_layouts;
  return $settings;
}