function DefaultSelection::validateTargetBundles

Validates a target_bundles element.

File

core/lib/Drupal/Core/Entity/Plugin/EntityReferenceSelection/DefaultSelection.php, line 333

Class

DefaultSelection
Default plugin implementation of the Entity Reference Selection plugin.

Namespace

Drupal\Core\Entity\Plugin\EntityReferenceSelection

Code

public static function validateTargetBundles($element, FormStateInterface $form_state, $form) {
    // If no checkboxes were checked for 'target_bundles', store NULL ("all
    // bundles are referenceable") rather than empty array ("no bundle is
    // referenceable" - typically happens when all referenceable bundles have
    // been deleted).
    if ($form_state->getValue($element['#parents']) === []) {
        $form_state->setValueForElement($element, NULL);
    }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.