You are here

public static function ParagraphSelection::targetTypeValidate in Paragraphs 8

Validate helper to have support for other entity reference widgets.

Parameters

$element:

FormStateInterface $form_state:

$form:

File

src/Plugin/EntityReferenceSelection/ParagraphSelection.php, line 147

Class

ParagraphSelection
Default plugin implementation of the Entity Reference Selection plugin.

Namespace

Drupal\paragraphs\Plugin\EntityReferenceSelection

Code

public static function targetTypeValidate($element, FormStateInterface $form_state, $form) {
  $values =& $form_state
    ->getValues();
  $element_values = NestedArray::getValue($values, $element['#parents']);
  $bundle_options = array();
  if ($element_values) {
    $enabled = 0;
    foreach ($element_values as $machine_name => $bundle_info) {
      if (isset($bundle_info['enabled']) && $bundle_info['enabled']) {
        $bundle_options[$machine_name] = $machine_name;
        $enabled++;
      }
    }

    // All disabled = all enabled.
    if ($enabled === 0) {
      $bundle_options = NULL;
    }
  }

  // New value parents.
  $parents = array_merge(array_slice($element['#parents'], 0, -1), array(
    'target_bundles',
  ));
  NestedArray::setValue($values, $parents, $bundle_options);
}