You are here

public function EntityReferenceHandlerBase::getHandlerSettings in CMS Content Sync 8

Same name and namespace in other branches
  1. 2.1.x src/Plugin/EntityReferenceHandlerBase.php \Drupal\cms_content_sync\Plugin\EntityReferenceHandlerBase::getHandlerSettings()
  2. 2.0.x src/Plugin/EntityReferenceHandlerBase.php \Drupal\cms_content_sync\Plugin\EntityReferenceHandlerBase::getHandlerSettings()

Get the handler settings.

Return the actual form elements for any additional settings for this handler.

Parameters

array $current_values: The current values that the user set, if any

string $type:: One of 'pull', 'push', 'both'

Return value

array

Overrides FieldHandlerBase::getHandlerSettings

1 call to EntityReferenceHandlerBase::getHandlerSettings()
MergeableEntityReferenceHandler::getHandlerSettings in src/Plugin/cms_content_sync/field_handler/MergeableEntityReferenceHandler.php
Get the handler settings.
2 methods override EntityReferenceHandlerBase::getHandlerSettings()
DefaultUserReferenceHandler::getHandlerSettings in src/Plugin/cms_content_sync/field_handler/DefaultUserReferenceHandler.php
Get the handler settings.
MergeableEntityReferenceHandler::getHandlerSettings in src/Plugin/cms_content_sync/field_handler/MergeableEntityReferenceHandler.php
Get the handler settings.

File

src/Plugin/EntityReferenceHandlerBase.php, line 25

Class

EntityReferenceHandlerBase
Providing a base implementation for any reference field type.

Namespace

Drupal\cms_content_sync\Plugin

Code

public function getHandlerSettings($current_values, $type = 'both') {
  $options = [];

  // Will be added in an upcoming release and recommended for paragraphs
  // and bricks.
  // Other entity types like media or taxonomy can use this as a performance
  // improvement as well.

  /*if(!$this->forceReferencedEntityEmbedding()) {
    $options = [
    'embed_referenced_entities' => [
    '#type' => 'checkbox',
    '#title' => 'Embed referenced entities',
    '#default_value' => $this->shouldEmbedReferencedEntities(),
    ],
    ];
    }*/
  $referenced_entity_types = $this
    ->getReferencedEntityTypes();
  if (!$this
    ->forcePushingReferencedEntities() && !$this
    ->forceEmbeddingReferencedEntities() && 'pull' !== $type && !in_array('view', $referenced_entity_types) && !in_array('classy_paragraphs_style', $referenced_entity_types)) {
    $options['export_referenced_entities'] = [
      '#type' => 'checkbox',
      '#title' => 'Push referenced entities',
      '#default_value' => isset($current_values['export_referenced_entities']) ? $current_values['export_referenced_entities'] : $this
        ->shouldPushReferencedEntities(true),
    ];
  }
  if ($this
    ->allowSubscribeFilter() && $this->flow && 'push' !== $type) {
    $type = $this->fieldDefinition
      ->getSetting('target_type');
    $bundles = $this->fieldDefinition
      ->getSetting('target_bundles');
    if (!$bundles) {
      $field_settings = $this->fieldDefinition
        ->getSettings();
      if (isset($field_settings['handler_settings']['target_bundles'])) {
        $bundles = $field_settings['handler_settings']['target_bundles'];
      }
    }
    global $config;
    $config_key = $this->entityTypeName . '-' . $this->bundleName . '-' . $this->fieldName;
    $disabled = !empty($config['cms_content_sync.flow.' . $this->flow
      ->id()]['sync_entities'][$config_key]['handler_settings']['subscribe_only_to']);
    $entities = [];
    $current = $disabled ? $config['cms_content_sync.flow.' . $this->flow
      ->id()]['sync_entities'][$config_key]['handler_settings']['subscribe_only_to'] : (empty($current_values['subscribe_only_to']) ? null : $current_values['subscribe_only_to']);
    if (!empty($current)) {
      $storage = \Drupal::entityTypeManager()
        ->getStorage($type);
      $repository = \Drupal::service('entity.repository');
      foreach ($current as $ref) {
        $entity = null;
        if (isset($ref['uuid'])) {
          $entity = $repository
            ->loadEntityByUuid($ref['type'], $ref['uuid']);
        }
        elseif (isset($ref['target_id'])) {
          $entity = $storage
            ->load($ref['target_id']);
        }
        if ($entity) {
          $entities[] = $entity;
        }
      }
    }
    $options['subscribe_only_to'] = [
      '#type' => 'entity_autocomplete',
      // The textfield component that the autocomplete inherits from sets this to 128 by default. We have no
      // restriction, so we set this to a very high number that can allow 100 terms.
      '#maxlength' => 4096,
      '#size' => 30,
      '#target_type' => $type,
      '#tags' => true,
      '#selection_settings' => [
        'target_bundles' => $bundles,
      ],
      '#title' => 'Subscribe only to',
      '#disabled' => $disabled,
      '#description' => $disabled ? $this
        ->t('Value provided via settings.php.') : '',
      '#default_value' => $entities,
    ];
  }
  return $options;
}