You are here

protected function ForwardForm::isValidDisplay in Forward 4.0.x

Same name and namespace in other branches
  1. 8.3 src/Form/ForwardForm.php \Drupal\forward\Form\ForwardForm::isValidDisplay()
  2. 8 src/Form/ForwardForm.php \Drupal\forward\Form\ForwardForm::isValidDisplay()
  3. 8.2 src/Form/ForwardForm.php \Drupal\forward\Form\ForwardForm::isValidDisplay()
  4. 4.x src/Form/ForwardForm.php \Drupal\forward\Form\ForwardForm::isValidDisplay()

Determine if a given display is valid for an entity.

1 call to ForwardForm::isValidDisplay()
ForwardForm::submitForm in src/Form/ForwardForm.php
Form submission handler.

File

src/Form/ForwardForm.php, line 708

Class

ForwardForm
Forward a page to a friend.

Namespace

Drupal\forward\Form

Code

protected function isValidDisplay(EntityInterface $entity, $view_mode) {

  // Assume the display is valid.
  $valid = FALSE;

  // Build display name.
  if ($entity
    ->getEntityType()
    ->hasKey('bundle')) {

    // Bundled entity types, e.g. node.
    $display_name = $entity
      ->getEntityTypeId() . '.' . $entity
      ->bundle() . '.' . $view_mode;
  }
  else {

    // Entity types without bundles, e.g. user.
    $display_name = $entity
      ->getEntityTypeId() . '.' . $view_mode;
  }

  // Attempt load.
  $display = $this->entityTypeManager
    ->getStorage('entity_view_display')
    ->load($display_name);
  if ($display) {

    // If the display loads, it exists in system
    // configuration, and status can be checked.
    if ($display
      ->status()) {
      $valid = TRUE;
    }
  }
  return $valid;
}