You are here

protected function ViewFormBase::prepareEntity in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/views_ui/src/ViewFormBase.php \Drupal\views_ui\ViewFormBase::prepareEntity()

Prepares the entity object before the form is built first.

Overrides EntityForm::prepareEntity

2 methods override ViewFormBase::prepareEntity()
ViewAddForm::prepareEntity in core/modules/views_ui/src/ViewAddForm.php
Prepares the entity object before the form is built first.
ViewDuplicateForm::prepareEntity in core/modules/views_ui/src/ViewDuplicateForm.php
Prepares the entity object before the form is built first.

File

core/modules/views_ui/src/ViewFormBase.php, line 47

Class

ViewFormBase
Base form for Views forms.

Namespace

Drupal\views_ui

Code

protected function prepareEntity() {

  // Determine the displays available for editing.
  if ($tabs = $this
    ->getDisplayTabs($this->entity)) {
    if (empty($this->displayID)) {

      // If a display isn't specified, use the first one after sorting by
      // #weight.
      uasort($tabs, 'Drupal\\Component\\Utility\\SortArray::sortByWeightProperty');
      foreach ($tabs as $id => $tab) {
        if (!isset($tab['#access']) || $tab['#access']) {
          $this->displayID = $id;
          break;
        }
      }
    }

    // If a display is specified, but we don't have access to it, return
    // an access denied page.
    if ($this->displayID && !isset($tabs[$this->displayID])) {
      throw new NotFoundHttpException();
    }
    elseif ($this->displayID && (isset($tabs[$this->displayID]['#access']) && !$tabs[$this->displayID]['#access'])) {
      throw new AccessDeniedHttpException();
    }
  }
  elseif ($this->displayID) {
    throw new NotFoundHttpException();
  }
}