/** * @param \Drupal\views\Entity\View $view * @param null $display_id * @return string */ protected function viewDisplayPaths(View $view, $display_id = null) { $all_paths = array(); $executable = $view->getExecutable(); $executable->initDisplay(); foreach ($executable->displayHandlers as $display) { if ($display->hasPath()) { $path = $display->getPath(); if (strpos($path, '%') === false) { // @see Views should expect and store a leading /. See: // https://www.drupal.org/node/2423913 $all_paths[] = '/' . $path; } else { $all_paths[] = '/' . $path; } if ($display_id !== null && $display_id == $display->getBaseId()) { return '/' . $path; } } } return implode(', ', array_unique($all_paths)); }
/** * Adds the array of display options to the view, with appropriate overrides. */ protected function addDisplays(View $view, $display_options, $form, FormStateInterface $form_state) { // Initialize and store the view executable to get the display plugin // instances. $executable = $view->getExecutable(); // Display: Master $default_display = $executable->newDisplay('default', 'Master', 'default'); foreach ($display_options['default'] as $option => $value) { $default_display->setOption($option, $value); } // Display: Page if (isset($display_options['page'])) { $display = $executable->newDisplay('page', 'Page', 'page_1'); // The page display is usually the main one (from the user's point of // view). Its options should therefore become the overall view defaults, // so that new displays which are added later automatically inherit them. $this->setDefaultOptions($display_options['page'], $display, $default_display); // Display: Feed (attached to the page). if (isset($display_options['feed'])) { $display = $executable->newDisplay('feed', 'Feed', 'feed_1'); $this->setOverrideOptions($display_options['feed'], $display, $default_display); } } // Display: Block. if (isset($display_options['block'])) { $display = $executable->newDisplay('block', 'Block', 'block_1'); // When there is no page, the block display options should become the // overall view defaults. if (!isset($display_options['page'])) { $this->setDefaultOptions($display_options['block'], $display, $default_display); } else { $this->setOverrideOptions($display_options['block'], $display, $default_display); } } // Display: REST export. if (isset($display_options['rest_export'])) { $display = $executable->newDisplay('rest_export', 'REST export', 'rest_export_1'); // If there is no page or block, the REST export display options should // become the overall view defaults. if (!isset($display_options['page']) && !isset($display_options['block'])) { $this->setDefaultOptions($display_options['rest_export'], $display, $default_display); } else { $this->setOverrideOptions($display_options['rest_export'], $display, $default_display); } } // Initialize displays and merge all plugin default values. $executable->mergeDefaults(); }