function EntityDisplayModeFormBase::exists

Same name in other branches
  1. 9 core/modules/field_ui/src/Form/EntityDisplayModeFormBase.php \Drupal\field_ui\Form\EntityDisplayModeFormBase::exists()
  2. 8.9.x core/modules/field_ui/src/Form/EntityDisplayModeFormBase.php \Drupal\field_ui\Form\EntityDisplayModeFormBase::exists()
  3. 10 core/modules/field_ui/src/Form/EntityDisplayModeFormBase.php \Drupal\field_ui\Form\EntityDisplayModeFormBase::exists()

Determines if the display mode already exists.

Parameters

string|int $entity_id: The entity ID.

array $element: The form element.

Return value

bool TRUE if the display mode exists, FALSE otherwise.

File

core/modules/field_ui/src/Form/EntityDisplayModeFormBase.php, line 152

Class

EntityDisplayModeFormBase
Provides the generic base class for entity display mode forms.

Namespace

Drupal\field_ui\Form

Code

public function exists($entity_id, array $element) {
    // Do not allow to add internal 'default' view mode.
    if ($entity_id == 'default') {
        return TRUE;
    }
    
    /** @var \Drupal\Core\Config\Entity\ConfigEntityStorageInterface $storage */
    $storage = $this->entityTypeManager
        ->getStorage($this->entity
        ->getEntityTypeId());
    return (bool) $storage->getQuery()
        ->condition('id', $element['#field_prefix'] . $entity_id)
        ->execute();
}

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