Update to Drupal 8.0.5. For more information, see https://www.drupal.org/node/2679347

This commit is contained in:
Pantheon Automation 2016-03-02 12:40:24 -08:00 committed by Greg Anderson
parent 2a9f1f148d
commit fd3b12cf27
251 changed files with 5439 additions and 957 deletions

View file

@ -14,9 +14,9 @@ views.argument_validator.php:
type: string
label: 'PHP validate code'
views.argument_validator.numeric:
type: boolean
label: 'Numeric'
views.argument_validator.*:
type: mapping
label: 'Default argument validator'
views.argument_validator_entity:
type: mapping

View file

@ -217,7 +217,7 @@ class EntityViewsData implements EntityHandlerInterface, EntityViewsDataInterfac
$data[$revision_data_table]['table']['group'] = $this->t('@entity_type revision', ['@entity_type' => $this->entityType->getLabel()]);
$data[$revision_data_table]['table']['entity revision'] = TRUE;
$data[$revision_data_table]['table']['join'][$revision_table] = array(
$data[$revision_table]['table']['join'][$revision_data_table] = array(
'left_field' => $revision_field,
'field' => $revision_field,
'type' => 'INNER',

View file

@ -2447,6 +2447,16 @@ abstract class DisplayPluginBase extends PluginBase implements DisplayPluginInte
$errors = array_merge($errors, $result);
}
// Check for missing relationships.
$relationships = array_keys($this->getHandlers('relationship'));
foreach (ViewExecutable::getHandlerTypes() as $type => $handler_type_info) {
foreach ($this->getHandlers($type) as $handler_id => $handler) {
if (!empty($handler->options['relationship']) && $handler->options['relationship'] != 'none' && !in_array($handler->options['relationship'], $relationships)) {
$errors[] = $this->t('The %handler_type %handler uses a relationship that has been removed.', array('%handler_type' => $handler_type_info['lstitle'], '%handler' => $handler->adminLabel()));
}
}
}
// Validate handlers.
foreach (ViewExecutable::getHandlerTypes() as $type => $info) {
foreach ($this->getHandlers($type) as $handler) {

View file

@ -39,7 +39,7 @@ interface DisplayRouterInterface extends DisplayPluginInterface {
public function alterRoutes(RouteCollection $collection);
/**
* Generates an URL to this display.
* Generates a URL to this display.
*
* @return \Drupal\Core\Url
* A URL object for the display.

View file

@ -1363,6 +1363,43 @@ abstract class FieldPluginBase extends HandlerBase implements FieldHandlerInterf
];
$path = $alter['path'];
// strip_tags() and viewsTokenReplace remove <front>, so check whether it's
// different to front.
if ($path != '<front>') {
// Use strip_tags as there should never be HTML in the path.
// However, we need to preserve special characters like " that were
// removed by SafeMarkup::checkPlain().
$path = Html::decodeEntities($this->viewsTokenReplace($alter['path'], $tokens));
// Tokens might contain <front>, so check for <front> again.
if ($path != '<front>') {
$path = strip_tags($path);
}
// Tokens might have resolved URL's, as is the case for tokens provided by
// Link fields, so all internal paths will be prefixed by base_path(). For
// proper further handling reset this to internal:/.
if (strpos($path, base_path()) === 0) {
$path = 'internal:/' . substr($path, strlen(base_path()));
}
// If we have no $path and no $alter['url'], we have nothing to work with,
// so we just return the text.
if (empty($path) && empty($alter['url'])) {
return $text;
}
// If no scheme is provided in the $path, assign the default 'http://'.
// This allows a url of 'www.example.com' to be converted to
// 'http://www.example.com'.
// Only do this when flag for external has been set, $path doesn't contain
// a scheme and $path doesn't have a leading /.
if ($alter['external'] && !parse_url($path, PHP_URL_SCHEME) && strpos($path, '/') !== 0) {
// There is no scheme, add the default 'http://' to the $path.
$path = "http://" . $path;
}
}
if (empty($alter['url'])) {
if (!parse_url($path, PHP_URL_SCHEME)) {
// @todo Views should expect and store a leading /. See
@ -1378,28 +1415,12 @@ abstract class FieldPluginBase extends HandlerBase implements FieldHandlerInterf
$path = $alter['url']->setOptions($options)->toUriString();
// strip_tags() removes <front>, so check whether its different to front.
if ($path != 'route:<front>') {
// Unescape Twig delimiters that may have been escaped by the
// Url::toUriString() call above, because we support twig tokens in
// rewrite settings of views fields.
// In that case the original path looks like
// internal:/admin/content/files/usage/{{ fid }}, which will be escaped by
// the toUriString() call above.
$path = preg_replace(['/(\%7B){2}(\%20)*/', '/(\%20)*(\%7D){2}/'], ['{{', '}}'], $path);
if (!empty($alter['path_case']) && $alter['path_case'] != 'none' && !$alter['url']->isRouted()) {
$path = str_replace($alter['path'], $this->caseTransform($alter['path'], $this->options['alter']['path_case']), $path);
}
// Use strip tags as there should never be HTML in the path.
// However, we need to preserve special characters like " that are escaped
// by \Drupal\Component\Utility\Html::escape().
$path = strip_tags(Html::decodeEntities($this->viewsTokenReplace($path, $tokens)));
if (!empty($alter['path_case']) && $alter['path_case'] != 'none' && !$alter['url']->isRouted()) {
$path = str_replace($alter['path'], $this->caseTransform($alter['path'], $this->options['alter']['path_case']), $path);
}
if (!empty($alter['replace_spaces'])) {
$path = str_replace(' ', '-', $path);
}
if (!empty($alter['replace_spaces'])) {
$path = str_replace(' ', '-', $path);
}
// Parse the URL and move any query and fragment parameters out of the path.
@ -1421,19 +1442,6 @@ abstract class FieldPluginBase extends HandlerBase implements FieldHandlerInterf
// $path now so we don't get query strings or fragments in the path.
$path = $url['path'];
// If no scheme is provided in the $path, assign the default 'http://'.
// This allows a url of 'www.example.com' to be converted to 'http://www.example.com'.
// Only do this on for external URLs.
if ($alter['external']) {
if (!isset($url['scheme'])) {
// There is no scheme, add the default 'http://' to the $path.
// Use the original $alter['path'] instead of the parsed version.
$path = "http://" . $alter['path'];
// Reset the $url array to include the new scheme.
$url = UrlHelper::parse($path);
}
}
if (isset($url['query'])) {
// Remove query parameters that were assigned a query string replacement
// token for which there is no value available.

View file

@ -1039,7 +1039,7 @@ abstract class WizardPluginBase extends PluginBase implements WizardInterface {
$display_options['pager']['type'] = 'none';
}
// If the user checked the pager checkbox use a full pager.
elseif (isset($page['pager'])) {
elseif (!empty($page['pager'])) {
$display_options['pager']['type'] = 'full';
}
// If the user doesn't have checked the checkbox use the pager which just

View file

@ -275,20 +275,28 @@ class ModuleTest extends ViewKernelTestBase {
public function testViewsEmbedView() {
$this->enableModules(array('user'));
/** @var \Drupal\Core\Render\RendererInterface $renderer */
$renderer = \Drupal::service('renderer');
$result = views_embed_view('test_argument');
$this->assertEqual(count($result['#view']->result), 5);
$renderer->renderPlain($result);
$this->assertEqual(count($result['view_build']['#view']->result), 5);
$result = views_embed_view('test_argument', 'default', 1);
$this->assertEqual(count($result['#view']->result), 1);
$renderer->renderPlain($result);
$this->assertEqual(count($result['view_build']['#view']->result), 1);
$result = views_embed_view('test_argument', 'default', '1,2');
$this->assertEqual(count($result['#view']->result), 2);
$renderer->renderPlain($result);
$this->assertEqual(count($result['view_build']['#view']->result), 2);
$result = views_embed_view('test_argument', 'default', '1,2', 'John');
$this->assertEqual(count($result['#view']->result), 1);
$renderer->renderPlain($result);
$this->assertEqual(count($result['view_build']['#view']->result), 1);
$result = views_embed_view('test_argument', 'default', '1,2', 'John,George');
$this->assertEqual(count($result['#view']->result), 2);
$renderer->renderPlain($result);
$this->assertEqual(count($result['view_build']['#view']->result), 2);
}
/**

View file

@ -7,6 +7,8 @@
namespace Drupal\views\Tests\Plugin;
use Drupal\node\Entity\Node;
use Drupal\node\Entity\NodeType;
use Drupal\views\Views;
use Drupal\views_test_data\Plugin\views\argument_default\ArgumentDefaultTest as ArgumentDefaultTestPlugin;
@ -23,14 +25,19 @@ class ArgumentDefaultTest extends PluginTestBase {
*
* @var array
*/
public static $testViews = array('test_view', 'test_argument_default_fixed', 'test_argument_default_current_user');
public static $testViews = array(
'test_view',
'test_argument_default_fixed',
'test_argument_default_current_user',
'test_argument_default_node',
);
/**
* Modules to enable.
*
* @var array
*/
public static $modules = array('node', 'views_ui');
public static $modules = array('node', 'views_ui', 'block');
protected function setUp() {
parent::setUp();
@ -80,7 +87,7 @@ class ArgumentDefaultTest extends PluginTestBase {
/**
* Tests the use of a default argument plugin that provides no options.
*/
function testArgumentDefaultNoOptions() {
public function testArgumentDefaultNoOptions() {
$admin_user = $this->drupalCreateUser(array('administer views', 'administer site configuration'));
$this->drupalLogin($admin_user);
@ -104,7 +111,7 @@ class ArgumentDefaultTest extends PluginTestBase {
/**
* Tests fixed default argument.
*/
function testArgumentDefaultFixed() {
public function testArgumentDefaultFixed() {
$random = $this->randomMachineName();
$view = Views::getView('test_argument_default_fixed');
$view->setDisplay();
@ -128,8 +135,37 @@ class ArgumentDefaultTest extends PluginTestBase {
//function testArgumentDefaultPhp() {}
/**
* @todo Test node default argument.
* Test node default argument.
*/
//function testArgumentDefaultNode() {}
public function testArgumentDefaultNode() {
// Create a user that has permission to place a view block.
$permissions = array(
'administer views',
'administer blocks',
'bypass node access',
'access user profiles',
'view all revisions',
);
$views_admin = $this->drupalCreateUser($permissions);
$this->drupalLogin($views_admin);
// Create nodes where should show themselves again as view block.
$node_type = NodeType::create(['type' => 'page', 'label' => 'Page']);
$node_type->save();
$node1 = Node::create(['title' => 'Test node 1', 'type' => 'page']);
$node1->save();
$node2 = Node::create(['title' => 'Test node 2', 'type' => 'page']);
$node2->save();
// Place the block, visit the pages that display the block, and check that
// the nodes we expect appear in the respective pages.
$id = 'view-block-id';
$this->drupalPlaceBlock("views_block:test_argument_default_node-block_1", ['id' => $id]);
$xpath = '//*[@id="block-' . $id . '"]';
$this->drupalGet('node/' . $node1->id());
$this->assertTrue(strpos($this->xpath($xpath)[0]->asXml(), $node1->getTitle()));
$this->drupalGet('node/' . $node2->id());
$this->assertTrue(strpos($this->xpath($xpath)[0]->asXml(), $node2->getTitle()));
}
}

View file

@ -23,7 +23,7 @@ class DisplayTest extends PluginTestBase {
*
* @var array
*/
public static $testViews = array('test_filter_groups', 'test_get_attach_displays', 'test_view', 'test_display_more', 'test_display_invalid', 'test_display_empty');
public static $testViews = array('test_filter_groups', 'test_get_attach_displays', 'test_view', 'test_display_more', 'test_display_invalid', 'test_display_empty', 'test_exposed_relationship_admin_ui');
/**
* Modules to enable.
@ -290,7 +290,7 @@ class DisplayTest extends PluginTestBase {
$config->save();
// Place the block display.
$block = $this->drupalPlaceBlock('views_block:test_display_invalid-block_1', array(), array('title' => 'Invalid display'));
$block = $this->drupalPlaceBlock('views_block:test_display_invalid-block_1', array('label' => 'Invalid display'));
$this->drupalGet('<front>');
$this->assertResponse(200);
@ -309,6 +309,31 @@ class DisplayTest extends PluginTestBase {
$this->assertNoBlockAppears($block);
}
/**
* Tests display validation when a required relationship is missing.
*/
public function testMissingRelationship() {
$view = Views::getView('test_exposed_relationship_admin_ui');
// Remove the relationship that is not used by other handlers.
$view->removeHandler('default', 'relationship', 'uid_1');
$errors = $view->validate();
// Check that no error message is shown.
$this->assertTrue(empty($errors['default']), 'No errors found when removing unused relationship.');
// Unset cached relationships (see DisplayPluginBase::getHandlers())
unset($view->display_handler->handlers['relationship']);
// Remove the relationship used by other handlers.
$view->removeHandler('default', 'relationship', 'uid');
// Validate display
$errors = $view->validate();
// Check that the error messages are shown.
$this->assertTrue(count($errors['default']) == 2, 'Error messages found for required relationship');
$this->assertEqual($errors['default'][0], t('The %handler_type %handler uses a relationship that has been removed.', array('%handler_type' => 'field', '%handler' => 'User: Last login')));
$this->assertEqual($errors['default'][1], t('The %handler_type %handler uses a relationship that has been removed.', array('%handler_type' => 'field', '%handler' => 'User: Created')));
}
/**
* Tests the outputIsEmpty method on the display.
*/

View file

@ -0,0 +1,66 @@
<?php
/**
* @file
* Contains \Drupal\views\Tests\Wizard\PagerTest.
*/
namespace Drupal\views\Tests\Wizard;
/**
* Tests the ability of the views wizard to create views without a pager.
*
* @group views
*/
class PagerTest extends WizardTestBase {
/**
* Tests the pager option.
*/
public function testPager() {
// Create nodes, each with a different creation time so that we have
// conditions that are meaningful for the use of a pager.
$this->drupalCreateContentType(array('type' => 'page'));
for ($i = 0; $i < 12; $i++) {
$this->drupalCreateNode(array('created' => REQUEST_TIME - $i));
}
// Make a View that uses a pager.
$path_with_pager = 'test-view-with-pager';
$this->createViewAtPath($path_with_pager, TRUE);
$this->drupalGet($path_with_pager);
// This technique for finding the existence of a pager
// matches that used in Drupal\views_ui\Tests\PreviewTest.php.
$elements = $this->xpath('//ul[contains(@class, :class)]/li', array(':class' => 'pager__items'));
$this->assertTrue(!empty($elements), 'Full pager found.');
// Make a View that does not have a pager.
$path_with_no_pager = 'test-view-without-pager';
$this->createViewAtPath($path_with_no_pager, FALSE);
$this->drupalGet($path_with_no_pager);
$elements = $this->xpath('//ul[contains(@class, :class)]/li', array(':class' => 'pager__items'));
$this->assertTrue(empty($elements), 'Full pager not found.');
}
/**
* Create a simple View of nodes at a given path.
*
* @param string $path
* The path at which the View should be created.
* @param bool $pager
* A boolean for whether the View created should use a pager.
*/
protected function createViewAtPath($path, $pager = TRUE) {
$view = array();
$view['label'] = $this->randomMachineName(16);
$view['id'] = strtolower($this->randomMachineName(16));
$view['show[sort]'] = 'node_field_data-created:ASC';
$view['page[create]'] = 1;
$view['page[title]'] = $this->randomMachineName(16);
$view['page[path]'] = $path;
$view['page[pager]'] = $pager;
$this->drupalPostForm('admin/structure/views/add', $view, t('Save and edit'));
}
}

View file

@ -41,14 +41,14 @@ class TaggedWithTest extends WizardTestBase {
protected $nodeTypeWithoutTags;
/**
* Node type without an autocomplete tagging field.
* The vocabulary used for the test tag field.
*
* @var \Drupal\taxonomy\VocabularyInterface
*/
protected $tagVocabulary;
/**
* Node type without an autocomplete tagging field.
* Holds the field storage for test tag field.
*
* @var \Drupal\field\FieldStorageConfigInterface
*/

View file

@ -8,12 +8,12 @@
namespace Drupal\views;
use Drupal\Component\Utility\Html;
use Drupal\Component\Utility\Tags;
use Drupal\Core\DependencyInjection\DependencySerializationTrait;
use Drupal\Core\Form\FormState;
use Drupal\Core\Routing\RouteProviderInterface;
use Drupal\Core\Session\AccountInterface;
use Drupal\views\Plugin\views\display\DisplayRouterInterface;
use Drupal\Component\Utility\Tags;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Exception\RouteNotFoundException;
@ -473,8 +473,10 @@ class ViewExecutable implements \Serializable {
}
/**
* Set the arguments that come to this view. Usually from the URL
* but possibly from elsewhere.
* Sets the arguments for the view.
*
* @param array $args
* The arguments passed to the view.
*/
public function setArguments(array $args) {
// The array keys of the arguments will be incorrect if set by
@ -497,7 +499,7 @@ class ViewExecutable implements \Serializable {
}
/**
* Change/Set the current page for the pager.
* Sets the current page for the pager.
*
* @param int $page
* The current page.
@ -519,7 +521,10 @@ class ViewExecutable implements \Serializable {
}
/**
* Get the current page from the pager.
* Gets the current page from the pager.
*
* @return int
* The current page.
*/
public function getCurrentPage() {
// If the pager is already initialized, pass it through to the pager.
@ -533,7 +538,10 @@ class ViewExecutable implements \Serializable {
}
/**
* Get the items per page from the pager.
* Gets the items per page from the pager.
*
* @return int
* The items per page.
*/
public function getItemsPerPage() {
// If the pager is already initialized, pass it through to the pager.
@ -547,7 +555,7 @@ class ViewExecutable implements \Serializable {
}
/**
* Set the items per page on the pager.
* Sets the items per page on the pager.
*
* @param int $items_per_page
* The items per page.
@ -567,7 +575,10 @@ class ViewExecutable implements \Serializable {
}
/**
* Get the pager offset from the pager.
* Gets the pager offset from the pager.
*
* @return int
* The pager offset.
*/
public function getOffset() {
// If the pager is already initialized, pass it through to the pager.
@ -581,7 +592,7 @@ class ViewExecutable implements \Serializable {
}
/**
* Set the offset on the pager.
* Sets the offset on the pager.
*
* @param int $offset
* The pager offset.
@ -603,7 +614,10 @@ class ViewExecutable implements \Serializable {
}
/**
* Determine if the pager actually uses a pager.
* Determines if the view uses a pager.
*
* @return bool
* TRUE if the view uses a pager, FALSE otherwise.
*/
public function usePager() {
if (!empty($this->pager)) {
@ -625,26 +639,36 @@ class ViewExecutable implements \Serializable {
}
/**
* Whether or not AJAX should be used.
*
* @see \Drupal\views\ViewExecutable::setAjaxEnabled().
* Determines whether or not AJAX should be used.
*
* @return bool
* TRUE if AJAX is enabled, FALSE otherwise.
*/
public function ajaxEnabled() {
return $this->ajaxEnabled;
}
/**
* Set the exposed filters input to an array. If unset they will be taken
* from \Drupal::request()->query when the time comes.
* Sets the exposed filters input to an array.
*
* @param string[] $filters
* The values taken from the view's exposed filters and sorts.
*/
public function setExposedInput($filters) {
$this->exposed_input = $filters;
}
/**
* Figure out what the exposed input for this view is.
* Figures out what the exposed input for this view is.
*
* They will be taken from \Drupal::request()->query or from
* something previously set on the view.
*
* @return string[]
* An array containing the exposed input values keyed by the filter and sort
* name.
*
* @see self::setExposedInput()
*/
public function getExposedInput() {
// Fill our input either from \Drupal::request()->query or from something
@ -678,7 +702,10 @@ class ViewExecutable implements \Serializable {
}
/**
* Set the display for this view and initialize the display handler.
* Sets the display for this view and initializes the display handler.
*
* @return true
* Always returns TRUE.
*/
public function initDisplay() {
if (isset($this->current_display)) {
@ -695,7 +722,7 @@ class ViewExecutable implements \Serializable {
}
/**
* Get the first display that is accessible to the user.
* Gets the first display that is accessible to the user.
*
* @param array|string $displays
* Either a single display id or an array of display ids.
@ -723,6 +750,7 @@ class ViewExecutable implements \Serializable {
* Gets the current display plugin.
*
* @return \Drupal\views\Plugin\views\display\DisplayPluginBase
* The current display plugin.
*/
public function getDisplay() {
if (!isset($this->display_handler)) {
@ -815,6 +843,7 @@ class ViewExecutable implements \Serializable {
* Gets the current style plugin.
*
* @return \Drupal\views\Plugin\views\style\StylePluginBase
* The current style plugin.
*/
public function getStyle() {
if (!isset($this->style_plugin)) {
@ -825,10 +854,13 @@ class ViewExecutable implements \Serializable {
}
/**
* Find and initialize the style plugin.
* Finds and initializes the style plugin.
*
* Note that arguments may have changed which style plugin we use, so
* check the view object first, then ask the display handler.
*
* @return bool
* TRUE if the style plugin was or could be initialized, FALSE otherwise.
*/
public function initStyle() {
if (isset($this->style_plugin)) {
@ -845,7 +877,7 @@ class ViewExecutable implements \Serializable {
}
/**
* Acquire and attach all of the handlers.
* Acquires and attaches all of the handlers.
*/
public function initHandlers() {
$this->initDisplay();
@ -858,9 +890,10 @@ class ViewExecutable implements \Serializable {
}
/**
* Get the current pager plugin.
* Gets the current pager plugin.
*
* @return \Drupal\views\Plugin\views\pager\PagerPluginBase
* The current pager plugin.
*/
public function getPager() {
if (!isset($this->pager)) {
@ -871,10 +904,10 @@ class ViewExecutable implements \Serializable {
}
/**
* Initialize the pager
* Initializes the pager.
*
* Like style initialization, pager initialization is held until late
* to allow for overrides.
* Like style initialization, pager initialization is held until late to allow
* for overrides.
*/
public function initPager() {
if (!isset($this->pager)) {
@ -897,7 +930,13 @@ class ViewExecutable implements \Serializable {
}
/**
* Render the pager, if necessary.
* Renders the pager, if necessary.
*
* @param string[] $exposed_input
* The input values from the exposed forms and sorts of the view.
*
* @return array|string
* The render array of the pager if it's set, blank string otherwise.
*/
public function renderPager($exposed_input) {
if (!empty($this->pager) && $this->pager->usePager()) {
@ -908,8 +947,12 @@ class ViewExecutable implements \Serializable {
}
/**
* Create a list of base tables eligible for this view. Used primarily
* for the UI. Display must be already initialized.
* Creates a list of base tables to be used by the view.
*
* This is used primarily for the UI. The display must be already initialized.
*
* @return array
* An array of base tables to be used by the view.
*/
public function getBaseTables() {
$base_tables = array(
@ -924,7 +967,7 @@ class ViewExecutable implements \Serializable {
}
/**
* Run the preQuery() on all active handlers.
* Runs the preQuery() on all active handlers.
*/
protected function _preQuery() {
foreach ($this::getHandlerTypes() as $key => $info) {
@ -939,7 +982,7 @@ class ViewExecutable implements \Serializable {
}
/**
* Run the postExecute() on all active handlers.
* Runs the postExecute() on all active handlers.
*/
protected function _postExecute() {
foreach ($this::getHandlerTypes() as $key => $info) {
@ -951,12 +994,13 @@ class ViewExecutable implements \Serializable {
}
/**
* Attach all of the handlers for each type.
* Attaches the views handler for the specific type.
*
* @param $key
* One of 'argument', 'field', 'sort', 'filter', 'relationship'
* @param $info
* The $info from getHandlerTypes for this object.
* @param string $key
* One of 'argument', 'field', 'sort', 'filter', 'relationship'.
* @param array $info
* An array of views handler types use in the view with additional
* information about them.
*/
protected function _initHandler($key, $info) {
// Load the requested items from the display onto the object.
@ -974,7 +1018,10 @@ class ViewExecutable implements \Serializable {
}
/**
* Build all the arguments.
* Builds all the arguments.
*
* @return bool
* TRUE if the arguments were built successfully, FALSE otherwise.
*/
protected function _buildArguments() {
// Initially, we want to build sorts and fields. This can change, though,
@ -1064,6 +1111,7 @@ class ViewExecutable implements \Serializable {
* Gets the current query plugin.
*
* @return \Drupal\views\Plugin\views\query\QueryPluginBase
* The current query plugin.
*/
public function getQuery() {
if (!isset($this->query)) {
@ -1074,7 +1122,10 @@ class ViewExecutable implements \Serializable {
}
/**
* Do some common building initialization.
* Initializes the query object for the view.
*
* @return true
* Always returns TRUE.
*/
public function initQuery() {
if (!empty($this->query)) {
@ -1097,7 +1148,14 @@ class ViewExecutable implements \Serializable {
}
/**
* Build the query for the view.
* Builds the query for the view.
*
* @param string $display_id
* The display ID of the view.
*
* @return bool|null
* TRUE if the view build process was successful, FALSE if setting the
* display fails or NULL if the view has been built already.
*/
public function build($display_id = NULL) {
if (!empty($this->built)) {
@ -1239,7 +1297,9 @@ class ViewExecutable implements \Serializable {
}
/**
* Internal method to build an individual set of handlers.
* Builds an individual set of handlers.
*
* This is an internal method.
*
* @todo Some filter needs this function, even it is internal.
*
@ -1280,14 +1340,14 @@ class ViewExecutable implements \Serializable {
}
/**
* Execute the view's query.
* Executes the view's query.
*
* @param string $display_id
* The machine name of the display, which should be executed.
*
* @return bool
* Return whether the executing was successful, for example an argument
* could stop the process.
* TRUE if the view execution was successful, FALSE otherwise. For example,
* an argument could stop the process.
*/
public function execute($display_id = NULL) {
if (empty($this->built)) {
@ -1311,8 +1371,9 @@ class ViewExecutable implements \Serializable {
$module_handler->invokeAll('views_pre_execute', array($this));
// Check for already-cached results.
/** @var \Drupal\views\Plugin\views\cache\CachePluginBase $cache */
if (!empty($this->live_preview)) {
$cache = $this->display_handler->getPlugin('cache', 'none');
$cache = Views::pluginManager('cache')->createInstance('none');
}
else {
$cache = $this->display_handler->getPlugin('cache');
@ -1340,7 +1401,7 @@ class ViewExecutable implements \Serializable {
}
/**
* Render this view for a certain display.
* Renders this view for a certain display.
*
* Note: You should better use just the preview function if you want to
* render a view.
@ -1348,8 +1409,9 @@ class ViewExecutable implements \Serializable {
* @param string $display_id
* The machine name of the display, which should be rendered.
*
* @return string|null
* Return the output of the rendered view or NULL if something failed in the process.
* @return array|null
* A renderable array containing the view output or NULL if the build
* process failed.
*/
public function render($display_id = NULL) {
$this->execute($display_id);
@ -1496,7 +1558,8 @@ class ViewExecutable implements \Serializable {
}
/**
* Execute the given display, with the given arguments.
* Executes the given display, with the given arguments.
*
* To be called externally by whatever mechanism invokes the view,
* such as a page callback, hook_block, etc.
*
@ -1506,6 +1569,15 @@ class ViewExecutable implements \Serializable {
* use of the display, such as setting page titles.
*
* If you simply want to view the display, use View::preview() instead.
*
* @param string $display_id
* The display ID of the view to be executed.
* @param string[] $args
* The arguments to be passed to the view.
*
* @return array|null
* A renderable array containing the view output or NULL if the display ID
* of the view to be executed doesn't exist.
*/
public function executeDisplay($display_id = NULL, $args = array()) {
if (empty($this->current_display) || $this->current_display != $this->chooseDisplay($display_id)) {
@ -1524,7 +1596,7 @@ class ViewExecutable implements \Serializable {
}
/**
* Preview the given display, with the given arguments.
* Previews the given display, with the given arguments.
*
* To be called externally, probably by an AJAX handler of some flavor.
* Can also be called when views are embedded, as this guarantees
@ -1534,6 +1606,10 @@ class ViewExecutable implements \Serializable {
* responsibility of the caller to check $view->access() or implement other
* access logic. To render the view normally with access checks, use
* views_embed_view() instead.
*
* @return array|null
* A renderable array containing the view output or NULL if the display ID
* of the view to be executed doesn't exist.
*/
public function preview($display_id = NULL, $args = array()) {
if (empty($this->current_display) || ((!empty($display_id)) && $this->current_display != $display_id)) {
@ -1552,8 +1628,10 @@ class ViewExecutable implements \Serializable {
}
/**
* Run attachments and let the display do what it needs to do prior
* to running.
* Runs attachments and lets the display do what it needs to before running.
*
* @param array @args
* An array of arguments from the URL that can be used by the view.
*/
public function preExecute($args = array()) {
$this->old_view[] = views_get_current_view();
@ -1577,7 +1655,7 @@ class ViewExecutable implements \Serializable {
}
/**
* Unset the current view, mostly.
* Unsets the current view, mostly.
*/
public function postExecute() {
// unset current view so we can be properly destructed later on.
@ -1591,7 +1669,7 @@ class ViewExecutable implements \Serializable {
}
/**
* Run attachment displays for the view.
* Runs attachment displays for the view.
*/
public function attachDisplays() {
if (!empty($this->is_attachment)) {
@ -1616,8 +1694,17 @@ class ViewExecutable implements \Serializable {
}
/**
* Determine if the given user has access to the view. Note that
* this sets the display handler if it hasn't been.
* Determines if the given user has access to the view.
*
* Note that this sets the display handler if it hasn't been set.
*
* @param string $displays
* The machine name of the display.
* @param \Drupal\Core\Session\AccountInterface $account
* The user object.
*
* @return bool
* TRUE if the user has access to the view, FALSE otherwise.
*/
public function access($displays = NULL, $account = NULL) {
// No one should have access to disabled views.
@ -1683,16 +1770,20 @@ class ViewExecutable implements \Serializable {
/**
* Gets the request object.
*
* @return \Symfony\Component\HttpFoundation\Request $request
* Returns the request object.
* @return \Symfony\Component\HttpFoundation\Request
* The request object.
*/
public function getRequest() {
return $this->request;
}
/**
* Get the view's current title. This can change depending upon how it
* was built.
* Gets the view's current title.
*
* This can change depending upon how it was built.
*
* @return string|false
* The view title, FALSE if the display is not set.
*/
public function getTitle() {
if (empty($this->display_handler)) {
@ -1717,9 +1808,12 @@ class ViewExecutable implements \Serializable {
}
/**
* Override the view's current title.
* Overrides the view's current title.
*
* The tokens in the title get's replaced before rendering.
*
* @return true
* Always returns TRUE.
*/
public function setTitle($title) {
$this->build_info['title'] = $title;
@ -1727,7 +1821,7 @@ class ViewExecutable implements \Serializable {
}
/**
* Force the view to build a title.
* Forces the view to build a title.
*/
public function buildTitle() {
$this->initDisplay();
@ -1753,6 +1847,7 @@ class ViewExecutable implements \Serializable {
* (optional) The display ID. The current display will be used by default.
*
* @return bool
* TRUE if the current display has a valid route available, FALSE otherwise.
*/
public function hasUrl($args = NULL, $display_id = NULL) {
if (!empty($this->override_url)) {
@ -1781,7 +1876,7 @@ class ViewExecutable implements \Serializable {
}
/**
* Get the URL for the current view.
* Gets the URL for the current view.
*
* This URL will be adjusted for arguments.
*
@ -1791,6 +1886,10 @@ class ViewExecutable implements \Serializable {
* (optional) Specify the display ID to link to, fallback to the current ID.
*
* @return \Drupal\Core\Url
* The URL of the current view.
*
* @throws \InvalidArgumentException
* Thrown when the current view doesn't have a route available.
*/
public function getUrl($args = NULL, $display_id = NULL) {
if (!empty($this->override_url)) {
@ -1863,7 +1962,7 @@ class ViewExecutable implements \Serializable {
* Gets the Url object associated with the display handler.
*
* @param string $display_id
* (Optional) The display id. ( Used only to detail an exception. )
* (optional) The display ID (used only to detail an exception).
*
* @return \Drupal\Core\Url
* The display handlers URL object.
@ -1880,7 +1979,10 @@ class ViewExecutable implements \Serializable {
}
/**
* Get the base path used for this view.
* Gets the base path used for this view.
*
* @return string|false
* The base path used for the view or FALSE if setting the display fails.
*/
public function getPath() {
if (!empty($this->override_path)) {
@ -1902,6 +2004,7 @@ class ViewExecutable implements \Serializable {
* injection.
*
* @return \Drupal\Core\Session\AccountInterface
* The current user.
*/
public function getUser() {
return $this->user;
@ -1918,8 +2021,7 @@ class ViewExecutable implements \Serializable {
}
/**
* Unset references so that a $view object may be properly garbage
* collected.
* Unsets references so that a $view object may be properly garbage collected.
*/
public function destroy() {
foreach ($this::getHandlerTypes() as $type => $info) {
@ -1977,8 +2079,9 @@ class ViewExecutable implements \Serializable {
}
/**
* Provide a list of views handler types used in a view, with some information
* about them.
* Provides a list of views handler types used in a view.
*
* This also provides some information about the views handler types.
*
* @return array
* An array of associative arrays containing:
@ -2243,7 +2346,7 @@ class ViewExecutable implements \Serializable {
* Returns whether admin links should be rendered on the view.
*
* @return bool
* Returns TRUE if admin links should be rendered, else FALSE.
* TRUE if admin links should be rendered, else FALSE.
*/
public function getShowAdminLinks() {
if (!isset($this->showAdminLinks)) {
@ -2264,7 +2367,7 @@ class ViewExecutable implements \Serializable {
}
/**
* Provide a full array of possible theme functions to try for a given hook.
* Provides a full array of possible theme functions to try for a given hook.
*
* @param string $hook
* The hook to use. This is the base theme/template name.
@ -2300,8 +2403,8 @@ class ViewExecutable implements \Serializable {
* Determines if this view has form elements.
*
* @return bool
* Returns TRUE if this view contains handlers with views form
* implementations, FALSE otherwise.
* TRUE if this view contains handlers with views form implementations,
* FALSE otherwise.
*/
public function hasFormElements() {
foreach ($this->field as $field) {

View file

@ -114,8 +114,17 @@ class ViewsDataHelper {
elseif (!empty($table_data['table'][$string])) {
$strings[$field][$key][$string] = $table_data['table'][$string];
}
// We don't have any help provided for this field. If a better
// description should be used for the Views UI you use
// hook_views_data_alter() in module.views.inc or implement a
// custom entity views_data handler.
// @see hook_views_data_alter()
// @see \Drupal\node\NodeViewsData
elseif ($string == 'help') {
$strings[$field][$key][$string] = '';
}
else {
if ($string != 'base' && $string != 'base') {
if ($string != 'base') {
$strings[$field][$key][$string] = SafeMarkup::format("Error: missing @component", array('@component' => $string));
}
}

View file

@ -0,0 +1,225 @@
langcode: en
status: true
dependencies:
config:
- node.type.page
module:
- node
- user
id: test_argument_default_node
label: 'Test argument_default node'
module: views
description: ''
tag: ''
base_table: node_field_data
base_field: nid
core: 8.x
display:
default:
display_plugin: default
id: default
display_title: Master
position: 0
display_options:
access:
type: perm
options:
perm: 'access content'
cache:
type: tag
options: { }
query:
type: views_query
options:
disable_sql_rewrite: false
distinct: false
replica: false
query_comment: ''
query_tags: { }
exposed_form:
type: basic
options:
submit_button: Apply
reset_button: false
reset_button_label: Reset
exposed_sorts_label: 'Sort by'
expose_sort_order: true
sort_asc_label: Asc
sort_desc_label: Desc
pager:
type: none
options:
items_per_page: null
offset: 0
style:
type: default
row:
type: fields
fields:
title:
id: title
table: node_field_data
field: title
settings:
link_to_entity: true
plugin_id: field
relationship: none
group_type: group
admin_label: ''
label: ''
exclude: false
alter:
alter_text: false
text: ''
make_link: false
path: ''
absolute: false
external: false
replace_spaces: false
path_case: none
trim_whitespace: false
alt: ''
rel: ''
link_class: ''
prefix: ''
suffix: ''
target: ''
nl2br: false
max_length: 0
word_boundary: true
ellipsis: true
more_link: false
more_link_text: ''
more_link_path: ''
strip_tags: false
trim: false
preserve_tags: ''
html: false
element_type: ''
element_class: ''
element_label_type: ''
element_label_class: ''
element_label_colon: true
element_wrapper_type: ''
element_wrapper_class: ''
element_default_classes: true
empty: ''
hide_empty: false
empty_zero: false
hide_alter_empty: true
click_sort_column: value
type: string
group_column: value
group_columns: { }
group_rows: true
delta_limit: 0
delta_offset: 0
delta_reversed: false
delta_first_last: false
multi_type: separator
separator: ', '
field_api_classes: false
filters:
status:
value: true
table: node_field_data
field: status
plugin_id: boolean
entity_type: node
entity_field: status
id: status
expose:
operator: ''
group: 1
type:
id: type
table: node_field_data
field: type
value:
page: page
entity_type: node
entity_field: type
plugin_id: bundle
sorts:
title:
id: title
table: node_field_data
field: title
order: DESC
entity_type: node
entity_field: title
plugin_id: standard
relationship: none
group_type: group
admin_label: ''
exposed: false
expose:
label: ''
title: 'Test argument_default node'
header: { }
footer: { }
empty: { }
relationships: { }
arguments:
nid:
id: nid
table: node_field_data
field: nid
relationship: none
group_type: group
admin_label: ''
default_action: default
exception:
value: all
title_enable: false
title: All
title_enable: false
title: ''
default_argument_type: node
default_argument_options: { }
default_argument_skip_url: false
summary_options:
base_path: ''
count: true
items_per_page: 25
override: false
summary:
sort_order: asc
number_of_records: 0
format: default_summary
specify_validation: false
validate:
type: none
fail: 'not found'
validate_options: { }
break_phrase: false
not: false
entity_type: node
entity_field: nid
plugin_id: node_nid
display_extenders: { }
cache_metadata:
max-age: -1
contexts:
- 'languages:language_content'
- 'languages:language_interface'
- url
- 'user.node_grants:view'
- user.permissions
tags: { }
block_1:
display_plugin: block
id: block_1
display_title: Block
position: 1
display_options:
display_extenders: { }
cache_metadata:
max-age: -1
contexts:
- 'languages:language_content'
- 'languages:language_interface'
- url
- 'user.node_grants:view'
- user.permissions
tags: { }

View file

@ -0,0 +1,229 @@
langcode: en
status: true
dependencies:
module:
- node
- user
id: test_argument_validation
label: ''
module: views
description: 'This view is used to test the argument validator schema.'
tag: ''
base_table: views_test_data
base_field: ''
core: '8'
display:
default:
display_options:
defaults:
fields: false
pager: false
sorts: false
arguments: false
fields:
age:
field: age
id: age
relationship: none
table: views_test_data
id:
field: id
id: id
relationship: none
table: views_test_data
name:
field: name
id: name
relationship: none
table: views_test_data
pager:
options:
offset: 0
type: none
sorts:
id:
field: id
id: id
order: ASC
relationship: none
table: views_test_data
arguments:
id:
id: id
table: views_test_data
field: id
relationship: none
group_type: group
admin_label: ''
default_action: ignore
exception:
value: all
title_enable: false
title: All
title_enable: false
title: ''
default_argument_type: fixed
default_argument_options:
argument: ''
default_argument_skip_url: false
summary_options:
base_path: ''
count: true
items_per_page: 25
override: false
summary:
sort_order: asc
number_of_records: 0
format: default_summary
specify_validation: false
validate:
type: numeric
fail: 'not found'
validate_options: { }
break_phrase: true
not: false
entity_type: node
entity_field: nid
plugin_id: numeric
name:
id: title
table: views_test_data
field: name
relationship: none
group_type: group
admin_label: ''
default_action: ignore
exception:
value: all
title_enable: false
title: All
title_enable: false
title: ''
default_argument_type: fixed
default_argument_options:
argument: ''
default_argument_skip_url: false
summary_options:
base_path: ''
count: true
items_per_page: 25
override: false
summary:
sort_order: asc
number_of_records: 0
format: default_summary
specify_validation: false
validate:
type: none
fail: 'not found'
validate_options: { }
glossary: false
limit: 0
case: none
path_case: none
transform_dash: false
break_phrase: true
entity_type: node
entity_field: name
plugin_id: string
user:
id: user
table: node_field_data
field: uid
relationship: none
group_type: group
admin_label: ''
default_action: ignore
exception:
value: all
title_enable: false
title: All
title_enable: false
title: ''
default_argument_type: fixed
default_argument_options:
argument: ''
default_argument_skip_url: false
summary_options:
base_path: ''
count: true
items_per_page: 25
override: false
summary:
sort_order: asc
number_of_records: 0
format: default_summary
specify_validation: false
validate:
type: 'entity:user'
fail: 'access denied'
validate_options:
access: true
operation: view
multiple: 0
restrict_roles: true
roles:
authenticated: authenticated
administrator: administrator
glossary: false
limit: 0
case: none
path_case: none
transform_dash: false
break_phrase: true
entity_type: node
entity_field: name
plugin_id: numeric
nid:
id: nid
table: node_field_data
field: nid
relationship: none
group_type: group
admin_label: ''
default_action: default
exception:
value: all
title_enable: false
title: All
title_enable: false
title: ''
default_argument_type: node
default_argument_options: { }
default_argument_skip_url: false
summary_options:
base_path: ''
count: true
items_per_page: 25
override: false
summary:
sort_order: asc
number_of_records: 0
format: default_summary
specify_validation: false
validate:
type: 'entity:node'
fail: 'not found'
validate_options:
bundles:
article: article
page: page
access: true
operation: view
multiple: 0
break_phrase: false
not: false
entity_type: node
entity_field: nid
plugin_id: node_nid
display_extenders: { }
display_plugin: default
display_title: Master
id: default
position: 0
cache_metadata:
max-age: -1
contexts:
- 'languages:language_interface'
- url
tags: { }

View file

@ -0,0 +1,281 @@
langcode: en
status: true
dependencies:
module:
- node
- user
id: test_exposed_relationship_admin_ui
label: test_exposed_relationship_admin_ui
module: views
description: ''
tag: ''
base_table: node
base_field: nid
core: 8.x
display:
default:
display_plugin: default
id: default
display_title: Master
position: 0
display_options:
access:
type: perm
options:
perm: 'access content'
cache:
type: none
options: { }
query:
type: views_query
options:
disable_sql_rewrite: false
distinct: false
replica: false
query_comment: ''
query_tags: { }
exposed_form:
type: basic
options:
submit_button: Apply
reset_button: false
reset_button_label: Reset
exposed_sorts_label: 'Sort by'
expose_sort_order: true
sort_asc_label: Asc
sort_desc_label: Desc
pager:
type: full
options:
items_per_page: 10
offset: 0
id: 0
total_pages: null
expose:
items_per_page: false
items_per_page_label: 'Items per page'
items_per_page_options: '5, 10, 25, 50'
items_per_page_options_all: false
items_per_page_options_all_label: '- All -'
offset: false
offset_label: Offset
tags:
previous: ' previous'
next: 'next '
first: '« first'
last: 'last »'
quantity: 9
style:
type: default
options:
grouping: { }
row_class: ''
default_row_class: true
uses_fields: false
row:
type: fields
options:
inline: { }
separator: ''
hide_empty: false
default_field_elements: true
fields:
title:
id: title
table: node_field_data
field: title
entity_type: node
entity_field: title
label: ''
alter:
alter_text: false
make_link: false
absolute: false
trim: false
word_boundary: false
ellipsis: false
strip_tags: false
html: false
hide_empty: false
empty_zero: false
link_to_node: true
plugin_id: node
relationship: none
group_type: group
admin_label: ''
exclude: false
element_type: ''
element_class: ''
element_label_type: ''
element_label_class: ''
element_label_colon: true
element_wrapper_type: ''
element_wrapper_class: ''
element_default_classes: true
empty: ''
hide_alter_empty: true
login:
id: login
table: users_field_data
field: login
relationship: uid
group_type: group
admin_label: ''
label: ''
exclude: false
alter:
alter_text: false
text: ''
make_link: false
path: ''
absolute: false
external: false
replace_spaces: false
path_case: none
trim_whitespace: false
alt: ''
rel: ''
link_class: ''
prefix: ''
suffix: ''
target: ''
nl2br: false
max_length: 0
word_boundary: true
ellipsis: true
more_link: false
more_link_text: ''
more_link_path: ''
strip_tags: false
trim: false
preserve_tags: ''
html: false
element_type: ''
element_class: ''
element_label_type: ''
element_label_class: ''
element_label_colon: false
element_wrapper_type: ''
element_wrapper_class: ''
element_default_classes: true
empty: ''
hide_empty: false
empty_zero: false
hide_alter_empty: true
date_format: fallback
custom_date_format: ''
timezone: ''
entity_type: user
entity_field: login
plugin_id: date
created:
id: created
table: users_field_data
field: created
relationship: uid
group_type: group
admin_label: ''
label: ''
exclude: false
alter:
alter_text: false
text: ''
make_link: false
path: ''
absolute: false
external: false
replace_spaces: false
path_case: none
trim_whitespace: false
alt: ''
rel: ''
link_class: ''
prefix: ''
suffix: ''
target: ''
nl2br: false
max_length: 0
word_boundary: true
ellipsis: true
more_link: false
more_link_text: ''
more_link_path: ''
strip_tags: false
trim: false
preserve_tags: ''
html: false
element_type: ''
element_class: ''
element_label_type: ''
element_label_class: ''
element_label_colon: false
element_wrapper_type: ''
element_wrapper_class: ''
element_default_classes: true
empty: ''
hide_empty: false
empty_zero: false
hide_alter_empty: true
date_format: fallback
custom_date_format: ''
timezone: ''
entity_type: user
entity_field: created
plugin_id: date
filters:
status:
value: true
table: node_field_data
field: status
plugin_id: boolean
entity_type: node
entity_field: status
id: status
expose:
operator: ''
group: 1
sorts:
created:
id: created
table: node_field_data
field: created
order: DESC
entity_type: node
entity_field: created
plugin_id: date
relationship: none
group_type: group
admin_label: ''
exposed: false
expose:
label: ''
granularity: second
header: { }
footer: { }
empty: { }
relationships:
uid:
id: uid
table: node_field_data
field: uid
relationship: none
group_type: group
admin_label: author
required: false
entity_type: node
entity_field: uid
plugin_id: standard
uid_1:
id: uid_1
table: node_field_data
field: uid
relationship: none
group_type: group
admin_label: 'author 2'
required: false
entity_type: node
entity_field: uid
plugin_id: standard
arguments: { }
display_extenders: { }

View file

@ -282,16 +282,21 @@ class EntityViewsDataTest extends UnitTestCase {
// Ensure the join information is set up properly.
// Tests the join definition between the base and the revision table.
$revision_data = $data['entity_test_mulrev_property_revision'];
$this->assertCount(2, $revision_data['table']['join']);
$revision_field_data = $data['entity_test_mulrev_property_revision'];
$this->assertCount(1, $revision_field_data['table']['join']);
$this->assertEquals([
'entity_test_mul_property_data' => [
'left_field' => 'revision_id', 'field' => 'revision_id', 'type' => 'INNER'
],
'entity_test_mulrev_revision' => [
], $revision_field_data['table']['join']);
$revision_base_data = $data['entity_test_mulrev_revision'];
$this->assertCount(1, $revision_base_data['table']['join']);
$this->assertEquals([
'entity_test_mulrev_property_revision' => [
'left_field' => 'revision_id', 'field' => 'revision_id', 'type' => 'INNER'
],
], $revision_data['table']['join']);
], $revision_base_data['table']['join']);
$this->assertFalse(isset($data['data_table']));
}
@ -321,12 +326,21 @@ class EntityViewsDataTest extends UnitTestCase {
// Ensure the join information is set up properly.
// Tests the join definition between the base and the revision table.
$revision_data = $data['entity_test_mulrev_property_revision'];
$this->assertCount(2, $revision_data['table']['join']);
$revision_field_data = $data['entity_test_mulrev_property_revision'];
$this->assertCount(1, $revision_field_data['table']['join']);
$this->assertEquals([
'entity_test_mulrev_field_data' => ['left_field' => 'revision_id', 'field' => 'revision_id', 'type' => 'INNER'],
'entity_test_mulrev_revision' => ['left_field' => 'revision_id', 'field' => 'revision_id', 'type' => 'INNER'],
], $revision_data['table']['join']);
'entity_test_mulrev_field_data' => [
'left_field' => 'revision_id', 'field' => 'revision_id', 'type' => 'INNER'
],
], $revision_field_data['table']['join']);
$revision_base_data = $data['entity_test_mulrev_revision'];
$this->assertCount(1, $revision_base_data['table']['join']);
$this->assertEquals([
'entity_test_mulrev_property_revision' => [
'left_field' => 'revision_id', 'field' => 'revision_id', 'type' => 'INNER'
],
], $revision_base_data['table']['join']);
$this->assertFalse(isset($data['data_table']));
}

View file

@ -343,6 +343,8 @@ class FieldPluginBaseTest extends UnitTestCase {
// External URL.
$data[] = ['https://www.drupal.org', [], [], '<a href="https://www.drupal.org">value</a>'];
$data[] = ['www.drupal.org', ['external' => TRUE], [], '<a href="http://www.drupal.org">value</a>'];
$data[] = ['', ['external' => TRUE], [], 'value'];
return $data;
}
@ -510,7 +512,7 @@ class FieldPluginBaseTest extends UnitTestCase {
$build =[
'#type' => 'inline_template',
'#template' => 'base:test-path/' . explode('/', $path)[1],
'#template' => 'test-path/' . explode('/', $path)[1],
'#context' => ['foo' => 123],
'#post_render' => [function() {}],
];
@ -549,6 +551,62 @@ class FieldPluginBaseTest extends UnitTestCase {
return $data;
}
/**
* Test rendering of a link with a path and options.
*
* @dataProvider providerTestRenderAsExternalLinkWithPathAndTokens
* @covers ::renderAsLink
*/
public function testRenderAsExternalLinkWithPathAndTokens($path, $tokens, $link_html, $context) {
$alter = [
'make_link' => TRUE,
'path' => $path,
'url' => '',
];
if (isset($context['alter'])) {
$alter += $context['alter'];
}
$this->setUpUrlIntegrationServices();
$this->setupDisplayWithEmptyArgumentsAndFields();
$this->executable->build_info['substitutions'] = $tokens;
$field = $this->setupTestField(['alter' => $alter]);
$field->field_alias = 'key';
$row = new ResultRow(['key' => 'value']);
$build = [
'#type' => 'inline_template',
'#template' => $path,
'#context' => ['foo' => $context['context_path']],
'#post_render' => [function() {}],
];
$this->renderer->expects($this->once())
->method('renderPlain')
->with($build)
->willReturn($context['context_path']);
$result = $field->advancedRender($row);
$this->assertEquals($link_html, $result);
}
/**
* Data provider for ::testRenderAsExternalLinkWithPathAndTokens().
*
* @return array
* Test data.
*/
public function providerTestRenderAsExternalLinkWithPathAndTokens() {
$data = [];
$data[] = ['{{ foo }}', ['{{ foo }}' => 'http://www.drupal.org'], '<a href="http://www.drupal.org">value</a>', ['context_path' => 'http://www.drupal.org']];
$data[] = ['{{ foo }}', ['{{ foo }}' => ''], 'value', ['context_path' => '']];
$data[] = ['{{ foo }}', ['{{ foo }}' => ''], 'value', ['context_path' => '', 'alter' => ['external' => TRUE]]];
$data[] = ['{{ foo }}', ['{{ foo }}' => '/test-path/123'], '<a href="/test-path/123">value</a>', ['context_path' => '/test-path/123']];
return $data;
}
/**
* Sets up a test field.
*

View file

@ -7,10 +7,16 @@
namespace Drupal\Tests\views\Unit;
use Drupal\Component\Plugin\PluginManagerInterface;
use Drupal\Core\DependencyInjection\ContainerBuilder;
use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\Core\Url;
use Drupal\Tests\UnitTestCase;
use Drupal\views\Entity\View;
use Drupal\views\Plugin\views\cache\CachePluginBase;
use Drupal\views\Plugin\views\cache\None as NoneCache;
use Drupal\views\Plugin\views\pager\None as NonePager;
use Drupal\views\Plugin\views\query\QueryPluginBase;
use Drupal\views\ViewExecutable;
use Symfony\Component\Routing\Route;
@ -76,6 +82,20 @@ class ViewExecutableTest extends UnitTestCase {
*/
protected $routeProvider;
/**
* The mocked none cache plugin.
*
* @var \Drupal\views\Plugin\views\cache\None|\PHPUnit_Framework_MockObject_MockObject
*/
protected $noneCache;
/**
* The mocked cache plugin that returns a successful result.
*
* @var \Drupal\views\Plugin\views\cache\None|\PHPUnit_Framework_MockObject_MockObject
*/
protected $successCache;
/**
* {@inheritdoc}
*/
@ -103,10 +123,26 @@ class ViewExecutableTest extends UnitTestCase {
->disableOriginalConstructor()
->getMock();
$module_handler = $this->getMockBuilder(ModuleHandlerInterface::class)
->getMock();
$this->noneCache = $this->getMockBuilder(NoneCache::class)
->disableOriginalConstructor()
->getMock();
$success_cache = $this->prophesize(CachePluginBase::class);
$success_cache->cacheGet('results')->willReturn(TRUE);
$this->successCache = $success_cache->reveal();
$cache_manager = $this->prophesize(PluginManagerInterface::class);
$cache_manager->createInstance('none')->willReturn($this->noneCache);
$translation = $this->getStringTranslationStub();
$container = new ContainerBuilder();
$container->set('string_translation', $translation);
$container->set('views.executable', $this->viewExecutableFactory);
$container->set('module_handler', $module_handler);
$container->set('plugin.manager.views.cache', $cache_manager->reveal());
\Drupal::setContainer($container);
}
@ -452,6 +488,11 @@ class ViewExecutableTest extends UnitTestCase {
$display = $this->getMockBuilder('Drupal\views\Plugin\views\display\DisplayPluginBase')
->disableOriginalConstructor()
->getMock();
$display->expects($this->any())
->method('getPlugin')
->with($this->equalTo('cache'))
->willReturn($this->successCache);
$display->display = $config['display']['default'];
$view->current_display = 'default';
@ -466,6 +507,10 @@ class ViewExecutableTest extends UnitTestCase {
->with('default')
->willReturn(TRUE);
foreach (array_keys($view->getHandlerTypes()) as $type) {
$view->$type = [];
}
return array($view, $display);
}
@ -565,4 +610,31 @@ class ViewExecutableTest extends UnitTestCase {
$this->assertNotContains('page:12', $view->element['#cache']['keys']);
}
/**
* @covers ::execute
*/
public function testCacheIsIgnoredDuringPreview() {
/** @var \Drupal\views\ViewExecutable|\PHPUnit_Framework_MockObject_MockObject $view */
/** @var \Drupal\views\Plugin\views\display\DisplayPluginBase|\PHPUnit_Framework_MockObject_MockObject $display */
list($view, $display) = $this->setupBaseViewAndDisplay();
// Pager needs to be set to avoid false test failures.
$view->pager = $this->getMockBuilder(NonePager::class)
->disableOriginalConstructor()
->getMock();
$query = $this->getMockBuilder(QueryPluginBase::class)
->disableOriginalConstructor()
->getMock();
$view->query = $query;
$view->built = TRUE;
$view->live_preview = TRUE;
$this->noneCache->expects($this->once())->method('cacheGet');
$query->expects($this->once())->method('execute');
$view->execute();
}
}

View file

@ -111,8 +111,10 @@ function hook_views_analyze(Drupal\views\ViewExecutable $view) {
* To provide views data for an entity, instead of implementing this hook,
* create a class implementing \Drupal\views\EntityViewsDataInterface and
* reference this in the "views" annotation in the entity class. The return
* value of the getViewsData() method on the interface is the same as this hook.
* See the @link entity_api Entity API topic @endlink for more information about
* value of the getViewsData() method on the interface is the same as this hook,
* and base class in \Drupal\views\EntityViewsData will take care of adding the
* basic Views tables and fields for your entity. See the
* @link entity_api Entity API topic @endlink for more information about
* entities.
*
* The data described with this hook is fetched and retrieved by
@ -137,6 +139,7 @@ function hook_views_data() {
// numeric_field INT(11) COMMENT 'Just a numeric field.',
// boolean_field INT(1) COMMENT 'Just an on/off field.',
// timestamp_field INT(8) COMMENT 'Just a timestamp field.',
// langcode VARCHAR(12) COMMENT 'Language code field.',
// PRIMARY KEY(nid)
// );
@ -186,25 +189,30 @@ function hook_views_data() {
// to do this for one-to-one joins, because otherwise your automatic join
// will add more rows to the view. It is also not a good idea to do this if
// most views won't need your table -- if that is the case, define a
// relationship instead (see the field section below).
// relationship instead (see below).
//
// If you've decided an automatic join is a good idea, here's how to do it:
// If you've decided an automatic join is a good idea, here's how to do it;
// the resulting SQL query will look something like this:
// ... FROM example_table et ... JOIN node_field_data nfd
// ON et.nid = nfd.nid AND ('extra' clauses will be here) ...
// although the table aliases will be different.
$data['example_table']['table']['join'] = array(
// Within the 'join' section, list one or more tables to automatically
// join to. In this example, every time 'node' is available in a view,
// 'example_table' will be too. The array keys here are the array keys
// for the other tables, given in their hook_views_data() implementations.
// If the table listed here is from another module's hook_views_data()
// implementation, make sure your module depends on that other module.
// join to. In this example, every time 'node_field_data' is available in
// a view, 'example_table' will be too. The array keys here are the array
// keys for the other tables, given in their hook_views_data()
// implementations. If the table listed here is from another module's
// hook_views_data() implementation, make sure your module depends on that
// other module.
'node_field_data' => array(
// Primary key field in node to use in the join.
// Primary key field in node_field_data to use in the join.
'left_field' => 'nid',
// Foreign key field in example_table to use in the join.
'field' => 'nid',
// An array of extra conditions on the join.
// 'extra' is an array of additional conditions on the join.
'extra' => array(
0 => array(
// Adds AND node.published = TRUE to the join.
// Adds AND node_field_data.published = TRUE to the join.
'field' => 'published',
'value' => TRUE,
),
@ -216,7 +224,8 @@ function hook_views_data() {
'numeric' => TRUE,
),
2 => array(
// Adds AND example_table.boolean_field <> node.published to the join.
// Adds AND example_table.boolean_field <>
// node_field_data.published to the join.
'field' => 'published',
'left_field' => 'boolean_field',
// The operator used, Defaults to "=".
@ -226,6 +235,39 @@ function hook_views_data() {
),
);
// You can also do a more complex join, where in order to get to a certain
// base table defined in a hook_views_data() implementation, you will join
// to a different table that Views knows how to auto-join to the base table.
// For instance, if another module that your module depends on had
// defined a table 'foo' with an automatic join to 'node_field_table' (as
// shown above), you could join to 'node_field_table' via the 'foo' table.
// Here's how to do this, and the resulting SQL query would look something
// like this:
// ... FROM example_table et ... JOIN foo foo
// ON et.nid = foo.nid AND ('extra' clauses will be here) ...
// JOIN node_field_data nfd ON (definition of the join from the foo
// module goes here) ...
// although the table aliases will be different.
$data['example_table']['table']['join']['node_field_data'] = array(
// 'node_field_data' above is the base we're joining to in Views.
// 'left_table' is the table we're actually joining to, in order to get to
// 'node_field_data'. It has to be something that Views knows how to join
// to 'node_field_data'.
'left_table' => 'foo',
'left_field' => 'nid',
'field' => 'nid',
// 'extra' is an array of additional conditions on the join.
'extra' => array(
// This syntax matches additional fields in the two tables:
// ... AND foo.langcode = example_table.langcode ...
array('left_field' => 'langcode', 'field' => 'langcode'),
// This syntax adds a condition on our table. 'operator' defaults to
// '=' for non-array values, or 'IN' for array values.
// ... AND example_table.numeric_field > 0 ...
array('field' => 'numeric_field', 'value' => 0, 'numeric' => TRUE, 'operator' => '>'),
),
);
// Other array elements at the top level of your table's array describe
// individual database table fields made available to Views. The array keys
// are the names (unique within the table) used by Views for the fields,
@ -258,15 +300,15 @@ function hook_views_data() {
'title' => t('Example content'),
'help' => t('Relate example content to the node content'),
// Define a relationship to the node table, so views whose base table is
// example_table can add a relationship to the node table. To make a
// Define a relationship to the node_field_data table, so views whose
// base table is example_table can add a relationship to nodes. To make a
// relationship in the other direction, you can:
// - Use hook_views_data_alter() -- see the function body example on that
// hook for details.
// - Use the implicit join method described above.
'relationship' => array(
// Views name of the table to join to for the relationship.
'base' => 'node',
'base' => 'node_field_data',
// Database field name in the other table to join on.
'base field' => 'nid',
// ID of relationship handler plugin to use.
@ -407,11 +449,11 @@ function hook_views_data() {
* @see hook_views_data()
*/
function hook_views_data_alter(array &$data) {
// Alter the title of the node:nid field in the Views UI.
$data['node']['nid']['title'] = t('Node-Nid');
// Alter the title of the node_field_data:nid field in the Views UI.
$data['node_field_data']['nid']['title'] = t('Node-Nid');
// Add an additional field to the users table.
$data['users']['example_field'] = array(
// Add an additional field to the users_field_data table.
$data['users_field_data']['example_field'] = array(
'title' => t('Example field'),
'help' => t('Some example content that references a user'),
@ -423,7 +465,7 @@ function hook_views_data_alter(array &$data) {
// Change the handler of the node title field, presumably to a handler plugin
// you define in your module. Give the ID of this plugin.
$data['node']['title']['field']['id'] = 'node_title';
$data['node_field_data']['title']['field']['id'] = 'node_title';
// Add a relationship that will allow a view whose base table is 'foo' (from
// another module) to have a relationship to 'example_table' (from my module),

View file

@ -331,3 +331,19 @@ function views_update_8003() {
/**
* @} End of "addtogroup updates-8.0.0-rc".
*/
/**
* @addtogroup updates-8.0.x
* @{
*/
/**
* Clear caches due to updated entity views data.
*/
function views_update_8004() {
// Empty update to cause a cache flush so that views data is rebuilt.
}
/**
* @} End of "addtogroup updates-8.0.x".
*/

View file

@ -728,6 +728,10 @@ function _views_query_tag_alter_condition(AlterableInterface $query, &$condition
* valid. But things like 'page' or 'block' should work here.
* @param ...
* Any additional parameters will be passed as arguments.
*
* @return array|null
* A renderable array containing the view output or NULL if the display ID
* of the view to be executed doesn't exist.
*/
function views_embed_view($name, $display_id = 'default') {
$args = func_get_args();
@ -739,7 +743,12 @@ function views_embed_view($name, $display_id = 'default') {
return;
}
return $view->preview($display_id, $args);
return [
'#type' => 'view',
'#name' => $name,
'#display_id' => $display_id,
'#arguments' => $args,
];
}
/**
@ -751,7 +760,7 @@ function views_embed_view($name, $display_id = 'default') {
* The display id. On the edit page for the view in question, you'll find
* a list of displays at the left side of the control area. "Master"
* will be at the top of that list. Hover your cursor over the name of the
* display you want to use. An URL will appear in the status bar of your
* display you want to use. A URL will appear in the status bar of your
* browser. This is usually at the bottom of the window, in the chrome.
* Everything after #views-tab- is the display ID, e.g. page_1.
* @param ...

View file

@ -397,6 +397,12 @@ function template_preprocess_views_view_table(&$variables) {
// A boolean variable which stores whether the table has a responsive class.
$responsive = FALSE;
// For the actual site we want to not render full URLs, because this would
// make pagers cacheable per URL, which is problematic in blocks, for example.
// For the actual live preview though the javascript relies on properly
// working URLs.
$route_name = !empty($view->live_preview) ? '<current>' : '<none>';
$query = tablesort_get_query_parameters();
if (isset($view->exposed_raw_input)) {
$query += $view->exposed_raw_input;
@ -438,9 +444,7 @@ function template_preprocess_views_view_table(&$variables) {
$link_options = array(
'query' => $query,
);
// It is ok to specify no URL path here as we will always reload the
// current page.
$url = new Url('<none>', [], $link_options);
$url = new Url($route_name, [], $link_options);
$variables['header'][$field]['url'] = $url->toString();
$variables['header'][$field]['content'] = $label;
$variables['header'][$field]['title'] = $title;

View file

@ -501,6 +501,9 @@ function views_field_default_views_data(FieldStorageConfigInterface $field_stora
$filter = 'numeric';
$argument = 'numeric';
$sort = 'standard';
if ($field_storage->getType() == 'boolean') {
$filter = 'boolean';
}
break;
case 'text':
case 'blob':