Update core 8.3.0

This commit is contained in:
Rob Davies 2017-04-13 15:53:35 +01:00
parent da7a7918f8
commit cd7a898e66
6144 changed files with 132297 additions and 87747 deletions

View file

@ -777,7 +777,7 @@ views_filter_group_item:
type: string
label: 'Operator'
value:
type: label
type: views.filter_value.[%parent.%parent.%parent.%parent.plugin_id]
label: 'Value'
views_relationship:

View file

@ -63,6 +63,12 @@ views.filter.in_operator:
reduce:
type: boolean
label: 'Reduce'
group_info:
mapping:
group_items:
sequence:
type: views.filter.group_item.in_operator
label: 'Group item'
views.filter.string:
type: views_filter
@ -93,8 +99,12 @@ views.filter_value.numeric:
type: string
label: 'Value'
views.filter_value.*:
type: string
label: 'Filter value'
views.filter_value.equality:
type: views.filter_value.numeric
type: string
label: 'Equality'
views.filter.many_to_one:
@ -109,18 +119,26 @@ views.filter.standard:
type: views_filter
label: 'Standard'
# Schema for the views group items.
views.filter.group_item.*:
type: views_filter_group_item
label: 'Default'
label: 'Group item'
views.filter.group_item.numeric:
views.filter.group_item.boolean:
type: views_filter_group_item
label: 'Group items'
mapping:
value:
type: views.filter_value.numeric
type: views.filter_value.string
views.filter.group_item.in_operator:
type: views_filter_group_item
mapping:
value:
type: views.filter_value.in_operator
# Schema for the views filter value.
views.filter_value.string:
type: string
views.filter_value.boolean:
type: string
@ -131,3 +149,26 @@ views.filter_value.combine:
views.filter.language:
type: views.filter.in_operator
label: 'Language'
views.filter_value.date:
type: views.filter_value.numeric
label: 'Date'
mapping:
type:
type: string
label: 'Type'
views.filter_value.datetime:
type: views.filter_value.numeric
label: 'Date'
mapping:
type:
type: string
label: 'Type'
views.filter_value.in_operator:
type: sequence
label: 'Values'
sequence:
type: string
label: 'Value'

View file

@ -128,13 +128,11 @@
/**
* @return {bool}
* If there is at least one parent with a view class return false.
*
* @todo remove .size() replace with .length.
*/
Drupal.views.ajaxView.prototype.filterNestedViews = function () {
// If there is at least one parent with a view class, this view
// is nested (e.g., an attachment). Bail.
return !this.$view.parents('.view').size();
return !this.$view.parents('.view').length;
};
/**

View file

@ -32,10 +32,10 @@ class HighlightCommand implements CommandInterface {
* {@inheritdoc}
*/
public function render() {
return array(
return [
'command' => 'viewsHighlight',
'selector' => $this->selector,
);
];
}
}

View file

@ -32,10 +32,10 @@ class ReplaceTitleCommand implements CommandInterface {
* {@inheritdoc}
*/
public function render() {
return array(
return [
'command' => 'viewsReplaceTitle',
'selector' => $this->title,
);
];
}
}

View file

@ -32,10 +32,10 @@ class ScrollTopCommand implements CommandInterface {
* {@inheritdoc}
*/
public function render() {
return array(
return [
'command' => 'viewsScrollTop',
'selector' => $this->selector,
);
];
}
}

View file

@ -33,10 +33,10 @@ class ShowButtonsCommand implements CommandInterface {
* {@inheritdoc}
*/
public function render() {
return array(
return [
'command' => 'viewsShowButtons',
'changed' => $this->changed,
);
];
}
}

View file

@ -15,9 +15,9 @@ class TriggerPreviewCommand implements CommandInterface {
* {@inheritdoc}
*/
public function render() {
return array(
return [
'command' => 'viewsTriggerPreview',
);
];
}
}

View file

@ -32,7 +32,7 @@ class ViewAjaxResponse extends AjaxResponse {
/**
* Gets the executed view of this response.
*
* @return \Drupal\views\ViewExecutable $view
* @return \Drupal\views\ViewExecutable
* The View executed on this ajax request.
*/
public function getView() {

View file

@ -44,7 +44,7 @@ class Analyzer {
*/
public function getMessages(ViewExecutable $view) {
$view->initDisplay();
$messages = $this->moduleHandler->invokeAll('views_analyze', array($view));
$messages = $this->moduleHandler->invokeAll('views_analyze', [$view]);
return $messages;
}
@ -57,13 +57,13 @@ class Analyzer {
*/
public function formatMessages(array $messages) {
if (empty($messages)) {
$messages = array(static::formatMessage(t('View analysis can find nothing to report.'), 'ok'));
$messages = [static::formatMessage(t('View analysis can find nothing to report.'), 'ok')];
}
$types = array('ok' => array(), 'warning' => array(), 'error' => array());
$types = ['ok' => [], 'warning' => [], 'error' => []];
foreach ($messages as $message) {
if (empty($types[$message['type']])) {
$types[$message['type']] = array();
$types[$message['type']] = [];
}
$types[$message['type']][] = $message['message'];
}
@ -73,10 +73,10 @@ class Analyzer {
$type .= ' messages';
$message = '';
if (count($messages) > 1) {
$item_list = array(
$item_list = [
'#theme' => 'item_list',
'#items' => $messages,
);
];
$message = drupal_render($item_list);
}
elseif ($messages) {
@ -115,8 +115,8 @@ class Analyzer {
* @return array
* A single formatted message, consisting of a key message and a key type.
*/
static function formatMessage($message, $type = 'error') {
return array('message' => $message, 'type' => $type);
public static function formatMessage($message, $type = 'error') {
return ['message' => $message, 'type' => $type];
}
}

View file

@ -114,7 +114,7 @@ class ViewAjaxController implements ContainerInjectionInterface {
$display_id = $request->request->get('view_display_id');
if (isset($name) && isset($display_id)) {
$args = $request->request->get('view_args');
$args = isset($args) && $args !== '' ? explode('/', $args) : array();
$args = isset($args) && $args !== '' ? explode('/', $args) : [];
// Arguments can be empty, make sure they are passed on as NULL so that
// argument validation is not triggered.
@ -132,7 +132,7 @@ class ViewAjaxController implements ContainerInjectionInterface {
// Remove all of this stuff from the query of the request so it doesn't
// end up in pagers and tablesort URLs.
foreach (array('view_name', 'view_display_id', 'view_args', 'view_path', 'view_dom_id', 'pager_element', 'view_base_path', AjaxResponseSubscriber::AJAX_REQUEST_PARAMETER) as $key) {
foreach (['view_name', 'view_display_id', 'view_args', 'view_path', 'view_dom_id', 'pager_element', 'view_base_path', AjaxResponseSubscriber::AJAX_REQUEST_PARAMETER] as $key) {
$request->query->remove($key);
$request->request->remove($key);
}

View file

@ -80,7 +80,7 @@ class DisplayPluginCollection extends DefaultLazyPluginCollection {
// display plugin isn't found.
catch (PluginException $e) {
$message = $e->getMessage();
drupal_set_message(t('@message', array('@message' => $message)), 'warning');
drupal_set_message(t('@message', ['@message' => $message]), 'warning');
}
// If no plugin instance has been created, return NULL.

View file

@ -17,16 +17,16 @@ class View extends RenderElement {
*/
public function getInfo() {
$class = get_class($this);
return array(
'#pre_render' => array(
array($class, 'preRenderViewElement'),
),
return [
'#pre_render' => [
[$class, 'preRenderViewElement'],
],
'#name' => NULL,
'#display_id' => 'default',
'#arguments' => array(),
'#arguments' => [],
'#embed' => TRUE,
'#cache' => [],
);
];
}
/**
@ -92,7 +92,7 @@ class View extends RenderElement {
}
if (empty($view->display_handler->getPluginDefinition()['returns_response'])) {
$element['#attributes']['class'][] = 'views-element-container';
$element['#theme_wrappers'] = array('container');
$element['#theme_wrappers'] = ['container'];
}
}

View file

@ -7,7 +7,7 @@ use Drupal\Core\Entity\Entity\EntityViewDisplay;
use Drupal\Core\Entity\EntityManagerInterface;
use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\Core\Language\LanguageManagerInterface;
use Drupal\views\Plugin\views\field\Field;
use Drupal\views\Plugin\views\field\EntityField;
use Drupal\views\Plugin\views\query\QueryPluginBase;
use Drupal\views\ResultRow;
use Drupal\views\ViewExecutable;
@ -111,13 +111,13 @@ class EntityFieldRenderer extends RendererBase {
*
* @param \Drupal\views\ResultRow $row
* A single row of the query result.
* @param \Drupal\views\Plugin\views\field\Field $field
* @param \Drupal\views\Plugin\views\field\EntityField $field
* (optional) A field to be rendered.
*
* @return array
* A renderable array for the entity data contained in the result row.
*/
public function render(ResultRow $row, Field $field = NULL) {
public function render(ResultRow $row, EntityField $field = NULL) {
// The method is called for each field in each result row. In order to
// leverage multiple-entity building of formatter output, we build the
// render arrays for all fields in all rows on the first call.
@ -259,7 +259,7 @@ class EntityFieldRenderer extends RendererBase {
protected function getRenderableFieldIds() {
$field_ids = [];
foreach ($this->view->field as $field_id => $field) {
if ($field instanceof Field && $field->relationship == $this->relationship) {
if ($field instanceof EntityField && $field->relationship == $this->relationship) {
$field_ids[] = $field_id;
}
}

View file

@ -30,10 +30,10 @@ trait EntityTranslationRenderTrait {
$view = $this->getView();
$rendering_language = $view->display_handler->getOption('rendering_language');
$langcode = NULL;
$dynamic_renderers = array(
$dynamic_renderers = [
'***LANGUAGE_entity_translation***' => 'TranslationLanguageRenderer',
'***LANGUAGE_entity_default***' => 'DefaultLanguageRenderer',
);
];
if (isset($dynamic_renderers[$rendering_language])) {
// Dynamic language set based on result rows or instance defaults.
$renderer = $dynamic_renderers[$rendering_language];

View file

@ -91,7 +91,7 @@ class View extends ConfigEntityBase implements ViewEntityInterface {
*
* @var array
*/
protected $display = array();
protected $display = [];
/**
* The name of the base field to use.
@ -182,15 +182,15 @@ class View extends ConfigEntityBase implements ViewEntityInterface {
}
}
$display_options = array(
$display_options = [
'display_plugin' => $plugin_id,
'id' => $id,
// Cast the display title to a string since it is an object.
// @see \Drupal\Core\StringTranslation\TranslatableMarkup
'display_title' => (string) $title,
'position' => $id === 'default' ? 0 : count($this->display),
'display_options' => array(),
);
'display_options' => [],
];
// Add the display options to the view.
$this->display[$id] = $display_options;
@ -293,7 +293,7 @@ class View extends ConfigEntityBase implements ViewEntityInterface {
// Sort the displays.
$display = $this->get('display');
ksort($display);
$this->set('display', array('default' => $display['default']) + $display);
$this->set('display', ['default' => $display['default']] + $display);
// @todo Check whether isSyncing is needed.
if (!$this->isSyncing()) {
@ -369,17 +369,17 @@ class View extends ConfigEntityBase implements ViewEntityInterface {
// If there is no information about displays available add at least the
// default display.
$values += array(
'display' => array(
'default' => array(
$values += [
'display' => [
'default' => [
'display_plugin' => 'default',
'id' => 'default',
'display_title' => 'Master',
'position' => 0,
'display_options' => array(),
),
)
);
'display_options' => [],
],
]
];
}
/**
@ -424,15 +424,15 @@ class View extends ConfigEntityBase implements ViewEntityInterface {
* {@inheritdoc}
*/
public function mergeDefaultDisplaysOptions() {
$displays = array();
$displays = [];
foreach ($this->get('display') as $key => $options) {
$options += array(
'display_options' => array(),
$options += [
'display_options' => [],
'display_plugin' => NULL,
'id' => NULL,
'display_title' => '',
'position' => NULL,
);
];
// Add the defaults for the display.
$displays[$key] = $options;
}

View file

@ -78,7 +78,7 @@ class EntityViewsData implements EntityHandlerInterface, EntityViewsDataInterfac
* @param \Drupal\Core\StringTranslation\TranslationInterface $translation_manager
* The translation manager.
*/
function __construct(EntityTypeInterface $entity_type, SqlEntityStorageInterface $storage_controller, EntityManagerInterface $entity_manager, ModuleHandlerInterface $module_handler, TranslationInterface $translation_manager) {
public function __construct(EntityTypeInterface $entity_type, SqlEntityStorageInterface $storage_controller, EntityManagerInterface $entity_manager, ModuleHandlerInterface $module_handler, TranslationInterface $translation_manager) {
$this->entityType = $entity_type;
$this->entityManager = $entity_manager;
$this->storage = $storage_controller;
@ -161,28 +161,28 @@ class EntityViewsData implements EntityHandlerInterface, EntityViewsDataInterfac
if ($label_key = $this->entityType->getKey('label')) {
if ($data_table) {
$data[$views_base_table]['table']['base']['defaults'] = array(
$data[$views_base_table]['table']['base']['defaults'] = [
'field' => $label_key,
'table' => $data_table,
);
];
}
else {
$data[$views_base_table]['table']['base']['defaults'] = array(
$data[$views_base_table]['table']['base']['defaults'] = [
'field' => $label_key,
);
];
}
}
// Entity types must implement a list_builder in order to use Views'
// entity operations field.
if ($this->entityType->hasListBuilderClass()) {
$data[$base_table]['operations'] = array(
'field' => array(
$data[$base_table]['operations'] = [
'field' => [
'title' => $this->t('Operations links'),
'help' => $this->t('Provides links to perform entity operations.'),
'id' => 'entity_operations',
),
);
],
];
}
if ($this->entityType->hasViewBuilderClass()) {
@ -215,26 +215,26 @@ class EntityViewsData implements EntityHandlerInterface, EntityViewsDataInterfac
$views_revision_base_table = $revision_data_table;
}
$data[$views_revision_base_table]['table']['entity revision'] = TRUE;
$data[$views_revision_base_table]['table']['base'] = array(
$data[$views_revision_base_table]['table']['base'] = [
'field' => $revision_field,
'title' => $this->t('@entity_type revisions', array('@entity_type' => $this->entityType->getLabel())),
);
'title' => $this->t('@entity_type revisions', ['@entity_type' => $this->entityType->getLabel()]),
];
// Join the revision table to the base table.
$data[$views_revision_base_table]['table']['join'][$views_base_table] = array(
$data[$views_revision_base_table]['table']['join'][$views_base_table] = [
'left_field' => $revision_field,
'field' => $revision_field,
'type' => 'INNER',
);
];
if ($revision_data_table) {
$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_table]['table']['join'][$revision_data_table] = array(
$data[$revision_table]['table']['join'][$revision_data_table] = [
'left_field' => $revision_field,
'field' => $revision_field,
'type' => 'INNER',
);
];
}
}
@ -404,7 +404,7 @@ class EntityViewsData implements EntityHandlerInterface, EntityViewsDataInterfac
* The modified views data field definition.
*/
protected function mapSingleFieldViewsData($table, $field_name, $field_type, $column_name, $column_type, $first, FieldDefinitionInterface $field_definition) {
$views_field = array();
$views_field = [];
// Provide a nicer, less verbose label for the first column within a field.
// @todo Introduce concept of the "main" column for a field, rather than

View file

@ -49,7 +49,7 @@ class RouteSubscriber extends RouteSubscriberBase {
*
* @var array
*/
protected $viewRouteNames = array();
protected $viewRouteNames = [];
/**
* Constructs a \Drupal\views\EventSubscriber\RouteSubscriber instance.
@ -76,7 +76,7 @@ class RouteSubscriber extends RouteSubscriberBase {
*/
public static function getSubscribedEvents() {
$events = parent::getSubscribedEvents();
$events[RoutingEvents::FINISHED] = array('routeRebuildFinished');
$events[RoutingEvents::FINISHED] = ['routeRebuildFinished'];
// Ensure to run after the entity resolver subscriber
// @see \Drupal\Core\EventSubscriber\EntityRouteAlterSubscriber
$events[RoutingEvents::ALTER] = ['onAlterRoutes', -175];
@ -89,7 +89,7 @@ class RouteSubscriber extends RouteSubscriberBase {
*/
protected function getViewsDisplayIDsWithRoute() {
if (!isset($this->viewsDisplayPairs)) {
$this->viewsDisplayPairs = array();
$this->viewsDisplayPairs = [];
// @todo Convert this method to some service.
$views = $this->getApplicableViews();
@ -156,7 +156,11 @@ class RouteSubscriber extends RouteSubscriberBase {
}
/**
* {@inheritdoc}
* Stores the new route names after they have been rebuilt.
*
* Callback for the RoutingEvents::FINISHED event.
*
* @see \Drupal\views\EventSubscriber::getSubscribedEvents()
*/
public function routeRebuildFinished() {
$this->reset();

View file

@ -144,6 +144,11 @@ class ViewsEntitySchemaSubscriber implements EntityTypeListenerInterface, EventS
$changes[] = static::REVISION_DATA_TABLE_REMOVAL;
}
// Stop here if no changes are needed.
if (empty($changes)) {
return;
}
/** @var \Drupal\views\Entity\View[] $all_views */
$all_views = $this->entityManager->getStorage('view')->loadMultiple(NULL);

View file

@ -14,7 +14,7 @@ class ExposedFormCache {
*
* @var array
*/
protected $cache = array();
protected $cache = [];
/**
* Save the Views exposed form for later use.
@ -56,7 +56,7 @@ class ExposedFormCache {
* Rests the form cache.
*/
public function reset() {
$this->cache = array();
$this->cache = [];
}
}

View file

@ -52,10 +52,10 @@ class ViewsExposedForm extends FormBase {
public function buildForm(array $form, FormStateInterface $form_state) {
// Don't show the form when batch operations are in progress.
if ($batch = batch_get() && isset($batch['current_set'])) {
return array(
return [
// Set the theme callback to be nothing to avoid errors in template_preprocess_views_exposed_form().
'#theme' => '',
);
];
}
// Make sure that we validate because this form might be submitted
@ -74,7 +74,7 @@ class ViewsExposedForm extends FormBase {
return $cache;
}
$form['#info'] = array();
$form['#info'] = [];
// Go through each handler and let it generate its exposed widget.
foreach ($view->display_handler->handlers as $type => $value) {
@ -100,16 +100,16 @@ class ViewsExposedForm extends FormBase {
}
}
$form['actions'] = array(
$form['actions'] = [
'#type' => 'actions'
);
$form['actions']['submit'] = array(
];
$form['actions']['submit'] = [
// Prevent from showing up in \Drupal::request()->query.
'#name' => '',
'#type' => 'submit',
'#value' => $this->t('Apply'),
'#id' => Html::getUniqueId('edit-submit-' . $view->storage->id()),
);
];
$form['#action'] = $view->hasUrl() ? $view->getUrl()->toString() : Url::fromRoute('<current>')->toString();
$form['#theme'] = $view->buildThemeFunctions('views_exposed_form');
@ -131,7 +131,7 @@ class ViewsExposedForm extends FormBase {
public function validateForm(array &$form, FormStateInterface $form_state) {
$view = $form_state->get('view');
foreach (array('field', 'filter') as $type) {
foreach (['field', 'filter'] as $type) {
/** @var \Drupal\views\Plugin\views\ViewsHandlerInterface[] $handlers */
$handlers = &$view->$type;
foreach ($handlers as $key => $handler) {
@ -148,9 +148,9 @@ class ViewsExposedForm extends FormBase {
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
// Form input keys that will not be included in $view->exposed_raw_data.
$exclude = array('submit', 'form_build_id', 'form_id', 'form_token', 'exposed_form_plugin', 'reset');
$exclude = ['submit', 'form_build_id', 'form_id', 'form_token', 'exposed_form_plugin', 'reset'];
$values = $form_state->getValues();
foreach (array('field', 'filter') as $type) {
foreach (['field', 'filter'] as $type) {
/** @var \Drupal\views\Plugin\views\ViewsHandlerInterface[] $handlers */
$handlers = &$form_state->get('view')->$type;
foreach ($handlers as $key => $info) {
@ -169,7 +169,7 @@ class ViewsExposedForm extends FormBase {
$view->exposed_data = $values;
$view->exposed_raw_input = [];
$exclude = array('submit', 'form_build_id', 'form_id', 'form_token', 'exposed_form_plugin', 'reset');
$exclude = ['submit', 'form_build_id', 'form_id', 'form_token', 'exposed_form_plugin', 'reset'];
/** @var \Drupal\views\Plugin\views\exposed_form\ExposedFormPluginBase $exposed_form_plugin */
$exposed_form_plugin = $view->display_handler->getPlugin('exposed_form');
$exposed_form_plugin->exposedFormSubmit($form, $form_state, $exclude);

View file

@ -151,19 +151,19 @@ class ViewsForm implements FormInterface, ContainerInjectionInterface {
// Add the base form ID.
$form_state->addBuildInfo('base_form_id', $this->getBaseFormId());
$form = array();
$form = [];
$query = $this->requestStack->getCurrentRequest()->query->all();
$query = UrlHelper::filterQueryParameters($query, array(), '');
$query = UrlHelper::filterQueryParameters($query, [], '');
$options = array('query' => $query);
$options = ['query' => $query];
$form['#action'] = $view->hasUrl() ? $view->getUrl()->setOptions($options)->toString() : Url::fromRoute('<current>')->setOptions($options)->toString();
// Tell the preprocessor whether it should hide the header, footer, pager,
// etc.
$form['show_view_elements'] = array(
$form['show_view_elements'] = [
'#type' => 'value',
'#value' => ($step == 'views_form_views_form') ? TRUE : FALSE,
);
];
$form_object = $this->getFormObject($form_state);
$form += $form_object->buildForm($form, $form_state, $view, $output);

View file

@ -30,15 +30,15 @@ class ViewsFormMainForm implements FormInterface {
// (below the exposed widgets).
$form['output']['#weight'] = 50;
$form['actions'] = array(
$form['actions'] = [
'#type' => 'actions',
);
$form['actions']['submit'] = array(
];
$form['actions']['submit'] = [
'#type' => 'submit',
'#value' => t('Save'),
);
];
$substitutions = array();
$substitutions = [];
foreach ($view->field as $field_name => $field) {
$form_element_name = $field_name;
if (method_exists($field, 'form_element_name')) {
@ -71,11 +71,11 @@ class ViewsFormMainForm implements FormInterface {
$form_element_row_id = $row_id;
}
$substitutions[] = array(
$substitutions[] = [
'placeholder' => '<!--form-item-' . $form_element_name . '--' . $form_element_row_id . '-->',
'field_name' => $form_element_name,
'row_id' => $form_element_row_id,
);
];
}
}
}
@ -89,10 +89,10 @@ class ViewsFormMainForm implements FormInterface {
}
}
$form['#substitutions'] = array(
$form['#substitutions'] = [
'#type' => 'value',
'#value' => $substitutions,
);
];
return $form;
}
@ -111,7 +111,7 @@ class ViewsFormMainForm implements FormInterface {
}
// Call the validate method on every area handler that has it.
foreach (array('header', 'footer') as $area) {
foreach (['header', 'footer'] as $area) {
foreach ($view->{$area} as $area_handler) {
if (method_exists($area_handler, 'viewsFormValidate')) {
$area_handler->viewsFormValidate($form, $form_state);
@ -134,7 +134,7 @@ class ViewsFormMainForm implements FormInterface {
}
// Call the submit method on every area handler that has it.
foreach (array('header', 'footer') as $area) {
foreach (['header', 'footer'] as $area) {
foreach ($view->{$area} as $area_handler) {
if (method_exists($area_handler, 'viewsFormSubmit')) {
$area_handler->viewsFormSubmit($form, $form_state);

View file

@ -20,22 +20,22 @@ use Drupal\views\Plugin\views\HandlerBase;
*/
class ManyToOneHelper {
function __construct($handler) {
public function __construct($handler) {
$this->handler = $handler;
}
public static function defineOptions(&$options) {
$options['reduce_duplicates'] = array('default' => FALSE);
$options['reduce_duplicates'] = ['default' => FALSE];
}
public function buildOptionsForm(&$form, FormStateInterface $form_state) {
$form['reduce_duplicates'] = array(
$form['reduce_duplicates'] = [
'#type' => 'checkbox',
'#title' => t('Reduce duplicates'),
'#description' => t("This filter can cause items that have more than one of the selected options to appear as duplicate results. If this filter causes duplicate results to occur, this checkbox can reduce those duplicates; however, the more terms it has to search for, the less performant the query will be, so use this with caution. Shouldn't be set on single-value fields, as it may cause values to disappear from display, if used on an incompatible field."),
'#default_value' => !empty($this->handler->options['reduce_duplicates']),
'#weight' => 4,
);
];
}
/**
@ -133,14 +133,14 @@ class ManyToOneHelper {
else {
if (!empty($view->many_to_one_tables[$field])) {
foreach ($view->many_to_one_tables[$field] as $value) {
$join->extra = array(
array(
$join->extra = [
[
'field' => $this->handler->realField,
'operator' => '!=',
'value' => $value,
'numeric' => !empty($this->definition['numeric']),
),
);
],
];
}
}
return $this->addTable($join);
@ -172,14 +172,14 @@ class ManyToOneHelper {
$join->type = 'LEFT';
if (!empty($this->handler->view->many_to_one_tables[$field])) {
foreach ($this->handler->view->many_to_one_tables[$field] as $value) {
$join->extra = array(
array(
$join->extra = [
[
'field' => $this->handler->realField,
'operator' => '!=',
'value' => $value,
'numeric' => !empty($this->handler->definition['numeric']),
),
);
],
];
}
}
@ -193,19 +193,19 @@ class ManyToOneHelper {
// We do one join per selected value.
if ($this->handler->operator != 'not') {
// Clone the join for each table:
$this->handler->tableAliases = array();
$this->handler->tableAliases = [];
foreach ($this->handler->value as $value) {
$join = $this->getJoin();
if ($this->handler->operator == 'and') {
$join->type = 'INNER';
}
$join->extra = array(
array(
$join->extra = [
[
'field' => $this->handler->realField,
'value' => $value,
'numeric' => !empty($this->handler->definition['numeric']),
),
);
],
];
// The table alias needs to be unique to this value across the
// multiple times the filter or argument is called by the view.
@ -229,14 +229,14 @@ class ManyToOneHelper {
else {
$join = $this->getJoin();
$join->type = 'LEFT';
$join->extra = array();
$join->extra = [];
$join->extraOperator = 'OR';
foreach ($this->handler->value as $value) {
$join->extra[] = array(
$join->extra[] = [
'field' => $this->handler->realField,
'value' => $value,
'numeric' => !empty($this->handler->definition['numeric']),
);
];
}
$this->handler->tableAlias = $this->addTable($join);
@ -296,9 +296,9 @@ class ManyToOneHelper {
else {
$operator = "$operator $placeholder";
}
$placeholders = array(
$placeholders = [
$placeholder => $value,
);
];
$this->handler->query->addWhereExpression($options['group'], "$field $operator", $placeholders);
}
else {
@ -310,7 +310,7 @@ class ManyToOneHelper {
$this->handler->query->addWhereExpression(0, "$field $operator");
}
else {
$this->handler->query->addWhereExpression(0, "$field $operator($placeholder)", array($placeholder => $value));
$this->handler->query->addWhereExpression(0, "$field $operator($placeholder)", [$placeholder => $value]);
}
}
else {
@ -318,7 +318,7 @@ class ManyToOneHelper {
$this->handler->query->addWhereExpression(0, "$field $operator");
}
else {
$this->handler->query->addWhereExpression(0, "$field $operator $placeholder", array($placeholder => $value));
$this->handler->query->addWhereExpression(0, "$field $operator $placeholder", [$placeholder => $value]);
}
}
}

View file

@ -5,6 +5,7 @@ namespace Drupal\views\Plugin\Block;
use Drupal\Component\Utility\Xss;
use Drupal\Core\Form\FormStateInterface;
use Drupal\views\Element\View;
use Drupal\Core\Entity\EntityInterface;
/**
* Provides a generic Views block.
@ -23,10 +24,31 @@ class ViewsBlock extends ViewsBlockBase {
public function build() {
$this->view->display_handler->preBlockBuild($this);
$args = [];
foreach ($this->view->display_handler->getHandlers('argument') as $argument_name => $argument) {
// Initialize the argument value. Work around a limitation in
// \Drupal\views\ViewExecutable::_buildArguments() that skips processing
// later arguments if an argument with default action "ignore" and no
// argument is provided.
$args[$argument_name] = $argument->options['default_action'] == 'ignore' ? 'all' : NULL;
if (!empty($this->context[$argument_name])) {
if ($value = $this->context[$argument_name]->getContextValue()) {
// Context values are often entities, but views arguments expect to
// receive just the entity ID, convert it.
if ($value instanceof EntityInterface) {
$value = $value->id();
}
$args[$argument_name] = $value;
}
}
}
// We ask ViewExecutable::buildRenderable() to avoid creating a render cache
// entry for the view output by passing FALSE, because we're going to cache
// the whole block instead.
if ($output = $this->view->buildRenderable($this->displayID, [], FALSE)) {
if ($output = $this->view->buildRenderable($this->displayID, array_values($args), FALSE)) {
// Before returning the block output, convert it to a renderable array
// with contextual links.
$this->addContextualLinks($output);
@ -52,7 +74,7 @@ class ViewsBlock extends ViewsBlockBase {
return $output;
}
return array();
return [];
}
/**
@ -95,7 +117,7 @@ class ViewsBlock extends ViewsBlockBase {
return $this->view->display_handler->blockForm($this, $form, $form_state);
}
return array();
return [];
}
/**

View file

@ -102,7 +102,7 @@ abstract class ViewsBlockBase extends BlockBase implements ContainerFactoryPlugi
* {@inheritdoc}
*/
public function defaultConfiguration() {
return array('views_label' => '');
return ['views_label' => ''];
}
/**
@ -122,39 +122,39 @@ abstract class ViewsBlockBase extends BlockBase implements ContainerFactoryPlugi
$form['#pre_render'][] = '\Drupal\views\Plugin\views\PluginBase::preRenderAddFieldsetMarkup';
// Allow to override the label on the actual page.
$form['views_label_checkbox'] = array(
$form['views_label_checkbox'] = [
'#type' => 'checkbox',
'#title' => $this->t('Override title'),
'#default_value' => !empty($this->configuration['views_label']),
);
];
$form['views_label_fieldset'] = array(
$form['views_label_fieldset'] = [
'#type' => 'fieldset',
'#states' => array(
'visible' => array(
array(
':input[name="settings[views_label_checkbox]"]' => array('checked' => TRUE),
),
),
),
);
'#states' => [
'visible' => [
[
':input[name="settings[views_label_checkbox]"]' => ['checked' => TRUE],
],
],
],
];
$form['views_label'] = array(
$form['views_label'] = [
'#title' => $this->t('Title'),
'#type' => 'textfield',
'#default_value' => $this->configuration['views_label'] ?: $this->view->getTitle(),
'#states' => array(
'visible' => array(
array(
':input[name="settings[views_label_checkbox]"]' => array('checked' => TRUE),
),
),
),
'#states' => [
'visible' => [
[
':input[name="settings[views_label_checkbox]"]' => ['checked' => TRUE],
],
],
],
'#fieldset' => 'views_label_fieldset',
);
];
if ($this->view->storage->access('edit') && \Drupal::moduleHandler()->moduleExists('views_ui')) {
$form['views_label']['#description'] = $this->t('Changing the title here means it cannot be dynamically altered anymore. (Try changing it directly in <a href=":url">@name</a>.)', array(':url' => \Drupal::url('entity.view.edit_display_form', array('view' => $this->view->storage->id(), 'display_id' => $this->displayID)), '@name' => $this->view->storage->label()));
$form['views_label']['#description'] = $this->t('Changing the title here means it cannot be dynamically altered anymore. (Try changing it directly in <a href=":url">@name</a>.)', [':url' => \Drupal::url('entity.view.edit_display_form', ['view' => $this->view->storage->id(), 'display_id' => $this->displayID]), '@name' => $this->view->storage->label()]);
}
else {
$form['views_label']['#description'] = $this->t('Changing the title here means it cannot be dynamically altered anymore.');
@ -194,7 +194,7 @@ abstract class ViewsBlockBase extends BlockBase implements ContainerFactoryPlugi
// array, so if the block contains a string of already-rendered markup,
// convert it to an array.
if (is_string($output)) {
$output = array('#markup' => $output);
$output = ['#markup' => $output];
}
// views_add_contextual_links() needs the following information in

View file

@ -17,16 +17,16 @@ class DefaultWizardDeriver extends DeriverBase {
public function getDerivativeDefinitions($base_plugin_definition) {
$views_data = Views::viewsData();
$base_tables = array_keys($views_data->fetchBaseTables());
$this->derivatives = array();
$this->derivatives = [];
foreach ($base_tables as $table) {
$views_info = $views_data->get($table);
if (empty($views_info['table']['wizard_id'])) {
$this->derivatives[$table] = array(
$this->derivatives[$table] = [
'id' => 'standard',
'base_table' => $table,
'title' => $views_info['table']['base']['title'],
'class' => 'Drupal\views\Plugin\views\wizard\Standard'
);
];
}
}
return parent::getDerivativeDefinitions($base_plugin_definition);

View file

@ -19,7 +19,7 @@ class ViewsBlock implements ContainerDeriverInterface {
*
* @var array
*/
protected $derivatives = array();
protected $derivatives = [];
/**
* The base plugin ID.
@ -82,6 +82,7 @@ class ViewsBlock implements ContainerDeriverInterface {
$executable = $view->getExecutable();
$executable->initDisplay();
foreach ($executable->displayHandlers as $display) {
/** @var \Drupal\views\Plugin\views\display\DisplayPluginInterface $display */
// Add a block plugin definition for each block display.
if (isset($display) && !empty($display->definition['uses_hook_block'])) {
$delta = $view->id() . '-' . $display->display['id'];
@ -100,15 +101,24 @@ class ViewsBlock implements ContainerDeriverInterface {
}
}
$this->derivatives[$delta] = array(
$this->derivatives[$delta] = [
'category' => $display->getOption('block_category'),
'admin_label' => $admin_label,
'config_dependencies' => array(
'config' => array(
'config_dependencies' => [
'config' => [
$view->getConfigDependencyName(),
)
)
);
],
],
];
// Look for arguments and expose them as context.
foreach ($display->getHandlers('argument') as $argument_name => $argument) {
/** @var \Drupal\views\Plugin\views\argument\ArgumentPluginBase $argument */
if ($context_definition = $argument->getContextDefinition()) {
$this->derivatives[$delta]['context'][$argument_name] = $context_definition;
}
}
$this->derivatives[$delta] += $base_plugin_definition;
}
}

View file

@ -38,7 +38,7 @@ class ViewsEntityArgumentValidator extends DeriverBase implements ContainerDeriv
*
* @var array
*/
protected $derivatives = array();
protected $derivatives = [];
/**
* Constructs an ViewsEntityArgumentValidator object.
@ -72,16 +72,16 @@ class ViewsEntityArgumentValidator extends DeriverBase implements ContainerDeriv
*/
public function getDerivativeDefinitions($base_plugin_definition) {
$entity_types = $this->entityManager->getDefinitions();
$this->derivatives = array();
$this->derivatives = [];
foreach ($entity_types as $entity_type_id => $entity_type) {
$this->derivatives[$entity_type_id] = array(
$this->derivatives[$entity_type_id] = [
'id' => 'entity:' . $entity_type_id,
'provider' => 'views',
'title' => $entity_type->getLabel(),
'help' => $this->t('Validate @label', array('@label' => $entity_type->getLabel())),
'help' => $this->t('Validate @label', ['@label' => $entity_type->getLabel()]),
'entity_type' => $entity_type_id,
'class' => $base_plugin_definition['class'],
);
];
}
return $this->derivatives;

View file

@ -21,7 +21,7 @@ class ViewsEntityRow implements ContainerDeriverInterface {
*
* @var array
*/
protected $derivatives = array();
protected $derivatives = [];
/**
* The base plugin ID that the derivative is for.
@ -89,16 +89,16 @@ class ViewsEntityRow implements ContainerDeriverInterface {
foreach ($this->entityManager->getDefinitions() as $entity_type_id => $entity_type) {
// Just add support for entity types which have a views integration.
if (($base_table = $entity_type->getBaseTable()) && $this->viewsData->get($base_table) && $this->entityManager->hasHandler($entity_type_id, 'view_builder')) {
$this->derivatives[$entity_type_id] = array(
$this->derivatives[$entity_type_id] = [
'id' => 'entity:' . $entity_type_id,
'provider' => 'views',
'title' => $entity_type->getLabel(),
'help' => t('Display the @label', array('@label' => $entity_type->getLabel())),
'base' => array($entity_type->getDataTable() ?: $entity_type->getBaseTable()),
'help' => t('Display the @label', ['@label' => $entity_type->getLabel()]),
'base' => [$entity_type->getDataTable() ?: $entity_type->getBaseTable()],
'entity_type' => $entity_type_id,
'display_types' => array('normal'),
'display_types' => ['normal'],
'class' => $base_plugin_definition['class'],
);
];
}
}

View file

@ -18,7 +18,7 @@ class ViewsExposedFilterBlock implements ContainerDeriverInterface {
*
* @var array
*/
protected $derivatives = array();
protected $derivatives = [];
/**
* The view storage.
@ -85,15 +85,15 @@ class ViewsExposedFilterBlock implements ContainerDeriverInterface {
// Add a block definition for the block.
if ($display->usesExposedFormInBlock()) {
$delta = $view->id() . '-' . $display->display['id'];
$desc = t('Exposed form: @view-@display_id', array('@view' => $view->id(), '@display_id' => $display->display['id']));
$this->derivatives[$delta] = array(
$desc = t('Exposed form: @view-@display_id', ['@view' => $view->id(), '@display_id' => $display->display['id']]);
$this->derivatives[$delta] = [
'admin_label' => $desc,
'config_dependencies' => array(
'config' => array(
'config_dependencies' => [
'config' => [
$view->getConfigDependencyName(),
)
)
);
]
]
];
$this->derivatives[$delta] += $base_plugin_definition;
}
}

View file

@ -67,7 +67,7 @@ class ViewsLocalTask extends DeriverBase implements ContainerDeriverInterface {
* {@inheritdoc}
*/
public function getDerivativeDefinitions($base_plugin_definition) {
$this->derivatives = array();
$this->derivatives = [];
$view_route_names = $this->state->get('views.view_route_names');
foreach ($this->getApplicableMenuViews() as $pair) {
@ -77,7 +77,7 @@ class ViewsLocalTask extends DeriverBase implements ContainerDeriverInterface {
$executable->setDisplay($display_id);
$menu = $executable->display_handler->getOption('menu');
if (in_array($menu['type'], array('tab', 'default tab'))) {
if (in_array($menu['type'], ['tab', 'default tab'])) {
$plugin_id = 'view.' . $executable->storage->id() . '.' . $display_id;
$route_name = $view_route_names[$executable->storage->id() . '.' . $display_id];
@ -87,11 +87,11 @@ class ViewsLocalTask extends DeriverBase implements ContainerDeriverInterface {
continue;
}
$this->derivatives[$plugin_id] = array(
$this->derivatives[$plugin_id] = [
'route_name' => $route_name,
'weight' => $menu['weight'],
'title' => $menu['title'],
) + $base_plugin_definition;
] + $base_plugin_definition;
// Default local tasks have themselves as root tab.
if ($menu['type'] == 'default tab') {
@ -117,7 +117,7 @@ class ViewsLocalTask extends DeriverBase implements ContainerDeriverInterface {
$menu = $executable->display_handler->getOption('menu');
// We already have set the base_route for default tabs.
if (in_array($menu['type'], array('tab'))) {
if (in_array($menu['type'], ['tab'])) {
$plugin_id = 'view.' . $executable->storage->id() . '.' . $display_id;
$view_route_name = $view_route_names[$executable->storage->id() . '.' . $display_id];

View file

@ -46,7 +46,7 @@ class ViewsMenuLink extends DeriverBase implements ContainerDeriverInterface {
* {@inheritdoc}
*/
public function getDerivativeDefinitions($base_plugin_definition) {
$links = array();
$links = [];
$views = Views::getApplicableViews('uses_menu_links');
foreach ($views as $data) {

View file

@ -97,14 +97,14 @@ class ViewsSelection extends PluginBase implements SelectionInterface, Container
*/
public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
$selection_handler_settings = $this->configuration['handler_settings'];
$view_settings = !empty($selection_handler_settings['view']) ? $selection_handler_settings['view'] : array();
$view_settings = !empty($selection_handler_settings['view']) ? $selection_handler_settings['view'] : [];
$displays = Views::getApplicableViews('entity_reference_display');
// Filter views that list the entity type we want, and group the separate
// displays by view.
$entity_type = $this->entityManager->getDefinition($this->configuration['target_type']);
$view_storage = $this->entityManager->getStorage('view');
$options = array();
$options = [];
foreach ($displays as $data) {
list($view_id, $display_id) = $data;
$view = $view_storage->load($view_id);
@ -118,36 +118,36 @@ class ViewsSelection extends PluginBase implements SelectionInterface, Container
// into 'view_name' and 'view_display' in the final submitted values, so
// we massage the data at validate time on the wrapping element (not
// ideal).
$form['view']['#element_validate'] = array(array(get_called_class(), 'settingsFormValidate'));
$form['view']['#element_validate'] = [[get_called_class(), 'settingsFormValidate']];
if ($options) {
$default = !empty($view_settings['view_name']) ? $view_settings['view_name'] . ':' . $view_settings['display_name'] : NULL;
$form['view']['view_and_display'] = array(
$form['view']['view_and_display'] = [
'#type' => 'select',
'#title' => $this->t('View used to select the entities'),
'#required' => TRUE,
'#options' => $options,
'#default_value' => $default,
'#description' => '<p>' . $this->t('Choose the view and display that select the entities that can be referenced.<br />Only views with a display of type "Entity Reference" are eligible.') . '</p>',
);
];
$default = !empty($view_settings['arguments']) ? implode(', ', $view_settings['arguments']) : '';
$form['view']['arguments'] = array(
$form['view']['arguments'] = [
'#type' => 'textfield',
'#title' => $this->t('View arguments'),
'#default_value' => $default,
'#required' => FALSE,
'#description' => $this->t('Provide a comma separated list of arguments to pass to the view.'),
);
];
}
else {
if ($this->currentUser->hasPermission('administer views') && $this->moduleHandler->moduleExists('views_ui')) {
$form['view']['no_view_help'] = array(
'#markup' => '<p>' . $this->t('No eligible views were found. <a href=":create">Create a view</a> with an <em>Entity Reference</em> display, or add such a display to an <a href=":existing">existing view</a>.', array(
$form['view']['no_view_help'] = [
'#markup' => '<p>' . $this->t('No eligible views were found. <a href=":create">Create a view</a> with an <em>Entity Reference</em> display, or add such a display to an <a href=":existing">existing view</a>.', [
':create' => Url::fromRoute('views_ui.add')->toString(),
':existing' => Url::fromRoute('entity.view.collection')->toString(),
)) . '</p>',
);
]) . '</p>',
];
}
else {
$form['view']['no_view_help']['#markup'] = '<p>' . $this->t('No eligible views were found.') . '</p>';
@ -191,18 +191,18 @@ class ViewsSelection extends PluginBase implements SelectionInterface, Container
// Check that the view is valid and the display still exists.
$this->view = Views::getView($view_name);
if (!$this->view || !$this->view->access($display_name)) {
drupal_set_message(t('The reference view %view_name cannot be found.', array('%view_name' => $view_name)), 'warning');
drupal_set_message(t('The reference view %view_name cannot be found.', ['%view_name' => $view_name]), 'warning');
return FALSE;
}
$this->view->setDisplay($display_name);
// Pass options to the display handler to make them available later.
$entity_reference_options = array(
$entity_reference_options = [
'match' => $match,
'match_operator' => $match_operator,
'limit' => $limit,
'ids' => $ids,
);
];
$this->view->displayHandlers->get($display_name)->setOption('entity_reference_options', $entity_reference_options);
return TRUE;
}
@ -214,13 +214,13 @@ class ViewsSelection extends PluginBase implements SelectionInterface, Container
$handler_settings = $this->configuration['handler_settings'];
$display_name = $handler_settings['view']['display_name'];
$arguments = $handler_settings['view']['arguments'];
$result = array();
$result = [];
if ($this->initializeView($match, $match_operator, $limit)) {
// Get the results.
$result = $this->view->executeDisplay($display_name, $arguments);
}
$return = array();
$return = [];
if ($result) {
foreach ($this->view->result as $row) {
$entity = $row->_entity;
@ -245,7 +245,7 @@ class ViewsSelection extends PluginBase implements SelectionInterface, Container
$handler_settings = $this->configuration['handler_settings'];
$display_name = $handler_settings['view']['display_name'];
$arguments = $handler_settings['view']['arguments'];
$result = array();
$result = [];
if ($this->initializeView(NULL, 'CONTAINS', 0, $ids)) {
// Get the results.
$entities = $this->view->executeDisplay($display_name, $arguments);
@ -272,14 +272,14 @@ class ViewsSelection extends PluginBase implements SelectionInterface, Container
// empty array instead.
$arguments_string = trim($element['arguments']['#value']);
if ($arguments_string === '') {
$arguments = array();
$arguments = [];
}
else {
// array_map() is called to trim whitespaces from the arguments.
$arguments = array_map('trim', explode(',', $arguments_string));
}
$value = array('view_name' => $view, 'display_name' => $display, 'arguments' => $arguments);
$value = ['view_name' => $view, 'display_name' => $display, 'arguments' => $arguments];
$form_state->setValueForElement($element, $value);
}

View file

@ -28,16 +28,16 @@ class ViewsMenuLinkForm extends MenuLinkDefaultForm {
public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
// Put the title field first.
$form['title'] = array(
$form['title'] = [
'#type' => 'textfield',
'#title' => $this->t('Title'),
// @todo Ensure that the view is not loaded with a localized title.
// https://www.drupal.org/node/2309507
'#default_value' => $this->menuLink->getTitle(),
'#weight' => -10,
);
];
$form['description'] = array(
$form['description'] = [
'#type' => 'textfield',
'#title' => $this->t('Description'),
'#description' => $this->t('Shown when hovering over the menu link.'),
@ -45,7 +45,7 @@ class ViewsMenuLinkForm extends MenuLinkDefaultForm {
// https://www.drupal.org/node/2309507
'#default_value' => $this->menuLink->getDescription(),
'#weight' => -5,
);
];
$form += parent::buildConfigurationForm($form, $form_state);
@ -56,10 +56,10 @@ class ViewsMenuLinkForm extends MenuLinkDefaultForm {
$id = $view->storage->id();
$label = $view->storage->label();
if ($this->moduleHandler->moduleExists('views_ui')) {
$message = $this->t('This link is provided by the Views module. The path can be changed by editing the view <a href=":url">@label</a>', array(':url' => \Drupal::url('entity.view.edit_form', array('view' => $id)), '@label' => $label));
$message = $this->t('This link is provided by the Views module. The path can be changed by editing the view <a href=":url">@label</a>', [':url' => \Drupal::url('entity.view.edit_form', ['view' => $id]), '@label' => $label]);
}
else {
$message = $this->t('This link is provided by the Views module from view %label.', array('%label' => $label));
$message = $this->t('This link is provided by the Views module from view %label.', ['%label' => $label]);
}
$form['info']['#title'] = $message;
return $form;

View file

@ -18,7 +18,7 @@ class ViewsMenuLink extends MenuLinkBase implements ContainerFactoryPluginInterf
/**
* {@inheritdoc}
*/
protected $overrideAllowed = array(
protected $overrideAllowed = [
'menu_name' => 1,
'parent' => 1,
'weight' => 1,
@ -26,7 +26,7 @@ class ViewsMenuLink extends MenuLinkBase implements ContainerFactoryPluginInterf
'enabled' => 1,
'title' => 1,
'description' => 1,
);
];
/**
* The entity manager.

View file

@ -59,9 +59,9 @@ class ViewsHandlerManager extends DefaultPluginManager implements FallbackPlugin
$this->viewsData = $views_data;
$this->handlerType = $handler_type;
$this->defaults = array(
$this->defaults = [
'plugin_type' => $handler_type,
);
];
}
/**
@ -86,7 +86,7 @@ class ViewsHandlerManager extends DefaultPluginManager implements FallbackPlugin
if (isset($data[$field][$this->handlerType])) {
$definition = $data[$field][$this->handlerType];
foreach (array('group', 'title', 'title short', 'label', 'help', 'real field', 'real table', 'entity type', 'entity field') as $key) {
foreach (['group', 'title', 'title short', 'label', 'help', 'real field', 'real table', 'entity type', 'entity field'] as $key) {
if (!isset($definition[$key])) {
// First check the field level.
if (!empty($data[$field][$key])) {
@ -111,13 +111,13 @@ class ViewsHandlerManager extends DefaultPluginManager implements FallbackPlugin
}
// Finally, use the 'broken' handler.
return $this->createInstance('broken', array('original_configuration' => $item));
return $this->createInstance('broken', ['original_configuration' => $item]);
}
/**
* {@inheritdoc}
*/
public function createInstance($plugin_id, array $configuration = array()) {
public function createInstance($plugin_id, array $configuration = []) {
$instance = parent::createInstance($plugin_id, $configuration);
if ($instance instanceof HandlerBase) {
$instance->setModuleHandler($this->moduleHandler);
@ -129,7 +129,7 @@ class ViewsHandlerManager extends DefaultPluginManager implements FallbackPlugin
/**
* {@inheritdoc}
*/
public function getFallbackPluginId($plugin_id, array $configuration = array()) {
public function getFallbackPluginId($plugin_id, array $configuration = []) {
return 'broken';
}

View file

@ -31,11 +31,11 @@ class ViewsPluginManager extends DefaultPluginManager {
$plugin_definition_annotation_name = 'Drupal\views\Annotation\Views' . Container::camelize($type);
parent::__construct("Plugin/views/$type", $namespaces, $module_handler, 'Drupal\views\Plugin\views\ViewsPluginInterface', $plugin_definition_annotation_name);
$this->defaults += array(
$this->defaults += [
'parent' => 'parent',
'plugin_type' => $type,
'register_theme' => TRUE,
);
];
$this->alterInfo('views_plugins_' . $type);
$this->setCacheBackend($cache_backend, "views:$type");

View file

@ -25,7 +25,7 @@ trait BrokenHandlerTrait {
* @see \Drupal\views\Plugin\views\PluginBase::defineOptions()
*/
public function defineOptions() {
return array();
return [];
}
/**
@ -55,28 +55,28 @@ trait BrokenHandlerTrait {
foreach ($this->definition['original_configuration'] as $key => $value) {
if (is_scalar($value)) {
$items[] = SafeMarkup::format('@key: @value', array('@key' => $key, '@value' => $value));
$items[] = SafeMarkup::format('@key: @value', ['@key' => $key, '@value' => $value]);
}
}
$description_bottom = t('Enabling the appropriate module will may solve this issue. Otherwise, check to see if there is a module update available.');
$form['description'] = array(
$form['description'] = [
'#type' => 'container',
'#attributes' => array(
'class' => array('js-form-item', 'form-item', 'description'),
),
'description_top' => array(
'#attributes' => [
'class' => ['js-form-item', 'form-item', 'description'],
],
'description_top' => [
'#markup' => '<p>' . $description_top . '</p>',
),
'detail_list' => array(
],
'detail_list' => [
'#theme' => 'item_list',
'#items' => $items,
),
'description_bottom' => array(
],
'description_bottom' => [
'#markup' => '<p>' . $description_bottom . '</p>',
),
);
],
];
}
/**

View file

@ -138,12 +138,12 @@ abstract class HandlerBase extends PluginBase implements ViewsHandlerInterface {
protected function defineOptions() {
$options = parent::defineOptions();
$options['id'] = array('default' => '');
$options['table'] = array('default' => '');
$options['field'] = array('default' => '');
$options['relationship'] = array('default' => 'none');
$options['group_type'] = array('default' => 'group');
$options['admin_label'] = array('default' => '');
$options['id'] = ['default' => ''];
$options['table'] = ['default' => ''];
$options['field'] = ['default' => ''];
$options['relationship'] = ['default' => 'none'];
$options['group_type'] = ['default' => 'group'];
$options['admin_label'] = ['default' => ''];
return $options;
}
@ -156,7 +156,7 @@ abstract class HandlerBase extends PluginBase implements ViewsHandlerInterface {
return $this->options['admin_label'];
}
$title = ($short && isset($this->definition['title short'])) ? $this->definition['title short'] : $this->definition['title'];
return $this->t('@group: @title', array('@group' => $this->definition['group'], '@title' => $title));
return $this->t('@group: @title', ['@group' => $this->definition['group'], '@title' => $title]);
}
/**
@ -248,36 +248,36 @@ abstract class HandlerBase extends PluginBase implements ViewsHandlerInterface {
// be moved into one because of the $form_state->getValues() hierarchy. Those
// elements can add a #fieldset => 'fieldset_name' property, and they'll
// be moved to their fieldset during pre_render.
$form['#pre_render'][] = array(get_class($this), 'preRenderAddFieldsetMarkup');
$form['#pre_render'][] = [get_class($this), 'preRenderAddFieldsetMarkup'];
parent::buildOptionsForm($form, $form_state);
$form['fieldsets'] = array(
$form['fieldsets'] = [
'#type' => 'value',
'#value' => array('more', 'admin_label'),
);
'#value' => ['more', 'admin_label'],
];
$form['admin_label'] = array(
$form['admin_label'] = [
'#type' => 'details',
'#title' => $this->t('Administrative title'),
'#weight' => 150,
);
$form['admin_label']['admin_label'] = array(
];
$form['admin_label']['admin_label'] = [
'#type' => 'textfield',
'#title' => $this->t('Administrative title'),
'#description' => $this->t('This title will be displayed on the views edit page instead of the default one. This might be useful if you have the same item twice.'),
'#default_value' => $this->options['admin_label'],
'#parents' => array('options', 'admin_label'),
);
'#parents' => ['options', 'admin_label'],
];
// This form is long and messy enough that the "Administrative title" option
// belongs in "Administrative title" fieldset at the bottom of the form.
$form['more'] = array(
$form['more'] = [
'#type' => 'details',
'#title' => $this->t('More'),
'#weight' => 200,
'#optional' => TRUE,
);
];
// Allow to alter the default values brought into the form.
// @todo Do we really want to keep this hook.
@ -329,13 +329,13 @@ abstract class HandlerBase extends PluginBase implements ViewsHandlerInterface {
$group_types[$id] = $aggregate['title'];
}
$form['group_type'] = array(
$form['group_type'] = [
'#type' => 'select',
'#title' => $this->t('Aggregation type'),
'#default_value' => $this->options['group_type'],
'#description' => $this->t('Select the aggregation function to use on this field.'),
'#options' => $group_types,
);
];
}
/**
@ -454,7 +454,7 @@ abstract class HandlerBase extends PluginBase implements ViewsHandlerInterface {
public function access(AccountInterface $account) {
if (isset($this->definition['access callback']) && function_exists($this->definition['access callback'])) {
if (isset($this->definition['access arguments']) && is_array($this->definition['access arguments'])) {
return call_user_func_array($this->definition['access callback'], array($account) + $this->definition['access arguments']);
return call_user_func_array($this->definition['access callback'], [$account] + $this->definition['access arguments']);
}
return $this->definition['access callback']($account);
}
@ -537,7 +537,7 @@ abstract class HandlerBase extends PluginBase implements ViewsHandlerInterface {
* Determine if this item is 'exposed', meaning it provides form elements
* to let users modify the view.
*
* @return TRUE/FALSE
* @return bool
*/
public function isExposed() {
return !empty($this->options['exposed']);
@ -587,7 +587,7 @@ abstract class HandlerBase extends PluginBase implements ViewsHandlerInterface {
/**
* {@inheritdoc}
*/
public function validate() { return array(); }
public function validate() { return []; }
/**
* {@inheritdoc}
@ -703,7 +703,7 @@ abstract class HandlerBase extends PluginBase implements ViewsHandlerInterface {
*/
public static function breakString($str, $force_int = FALSE) {
$operator = NULL;
$value = array();
$value = [];
// Determine if the string has 'or' operators (plus signs) or 'and'
// operators (commas) and split the string accordingly.
@ -726,7 +726,7 @@ abstract class HandlerBase extends PluginBase implements ViewsHandlerInterface {
$value = array_map('intval', $value);
}
return (object) array('value' => $value, 'operator' => $operator);
return (object) ['value' => $value, 'operator' => $operator];
}
/**

View file

@ -66,7 +66,7 @@ abstract class PluginBase extends ComponentPluginBase implements ContainerFactor
*
* @var array
*/
public $options = array();
public $options = [];
/**
* The top object of a view.
@ -155,7 +155,7 @@ abstract class PluginBase extends ComponentPluginBase implements ContainerFactor
* @return array
* Returns the options of this handler/plugin.
*/
protected function defineOptions() { return array(); }
protected function defineOptions() { return []; }
/**
* Fills up the options of the plugin with defaults.
@ -175,7 +175,7 @@ abstract class PluginBase extends ComponentPluginBase implements ContainerFactor
protected function setOptionDefaults(array &$storage, array $options) {
foreach ($options as $option => $definition) {
if (isset($definition['contains'])) {
$storage[$option] = array();
$storage[$option] = [];
$this->setOptionDefaults($storage[$option], $definition['contains']);
}
else {
@ -231,7 +231,7 @@ abstract class PluginBase extends ComponentPluginBase implements ContainerFactor
}
if (!isset($storage[$key]) || !is_array($storage[$key])) {
$storage[$key] = array();
$storage[$key] = [];
}
// If we're just unpacking our known options, and we're dropping an
@ -242,7 +242,7 @@ abstract class PluginBase extends ComponentPluginBase implements ContainerFactor
continue;
}
$this->unpackOptions($storage[$key], $value, isset($definition[$key]['contains']) ? $definition[$key]['contains'] : array(), $all, FALSE);
$this->unpackOptions($storage[$key], $value, isset($definition[$key]['contains']) ? $definition[$key]['contains'] : [], $all, FALSE);
}
elseif ($all || !empty($definition[$key])) {
$storage[$key] = $value;
@ -265,7 +265,7 @@ abstract class PluginBase extends ComponentPluginBase implements ContainerFactor
// be moved into one because of the $form_state->getValues() hierarchy. Those
// elements can add a #fieldset => 'fieldset_name' property, and they'll
// be moved to their fieldset during pre_render.
$form['#pre_render'][] = array(get_class($this), 'preRenderAddFieldsetMarkup');
$form['#pre_render'][] = [get_class($this), 'preRenderAddFieldsetMarkup'];
}
/**
@ -293,7 +293,7 @@ abstract class PluginBase extends ComponentPluginBase implements ContainerFactor
/**
* {@inheritdoc}
*/
public function validate() { return array(); }
public function validate() { return []; }
/**
* {@inheritdoc}
@ -323,8 +323,8 @@ abstract class PluginBase extends ComponentPluginBase implements ContainerFactor
/**
* {@inheritdoc}
*/
public function globalTokenReplace($string = '', array $options = array()) {
return \Drupal::token()->replace($string, array('view' => $this->view), $options);
public function globalTokenReplace($string = '', array $options = []) {
return \Drupal::token()->replace($string, ['view' => $this->view], $options);
}
/**
@ -347,7 +347,7 @@ abstract class PluginBase extends ComponentPluginBase implements ContainerFactor
return Xss::filterAdmin($text);
}
$twig_tokens = array();
$twig_tokens = [];
foreach ($tokens as $token => $replacement) {
// Twig wants a token replacement array stripped of curly-brackets.
// Some Views tokens come with curly-braces, others do not.
@ -371,11 +371,11 @@ abstract class PluginBase extends ComponentPluginBase implements ContainerFactor
$parts = explode('.', $token);
$top = array_shift($parts);
assert('preg_match(\'/^[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*$/\', $top) === 1', 'Tokens need to be valid Twig variables.');
$token_array = array(array_pop($parts) => $replacement);
$token_array = [array_pop($parts) => $replacement];
foreach (array_reverse($parts) as $key) {
// The key could also be numeric (array index) so allow that.
assert('is_numeric($key) || (preg_match(\'/^[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*$/\', $key) === 1)', 'Tokens need to be valid Twig variables.');
$token_array = array($key => $token_array);
$token_array = [$key => $token_array];
}
if (!isset($twig_tokens[$top])) {
$twig_tokens[$top] = [];
@ -389,7 +389,7 @@ abstract class PluginBase extends ComponentPluginBase implements ContainerFactor
// Otherwise, Xss::filterAdmin could remove valid Twig syntax before the
// template is parsed.
$build = array(
$build = [
'#type' => 'inline_template',
'#template' => $text,
'#context' => $twig_tokens,
@ -398,7 +398,7 @@ abstract class PluginBase extends ComponentPluginBase implements ContainerFactor
return Xss::filterAdmin($children);
}
],
);
];
// Currently you cannot attach assets to tokens with
// Renderer::renderPlain(). This may be unnecessarily limiting. Consider
@ -414,15 +414,15 @@ abstract class PluginBase extends ComponentPluginBase implements ContainerFactor
/**
* {@inheritdoc}
*/
public function getAvailableGlobalTokens($prepared = FALSE, array $types = array()) {
public function getAvailableGlobalTokens($prepared = FALSE, array $types = []) {
$info = \Drupal::token()->getInfo();
// Site and view tokens should always be available.
$types += array('site', 'view');
$types += ['site', 'view'];
$available = array_intersect_key($info['tokens'], array_flip($types));
// Construct the token string for each token.
if ($prepared) {
$prepared = array();
$prepared = [];
foreach ($available as $type => $tokens) {
foreach (array_keys($tokens) as $token) {
$prepared[$type][] = "[$type:$token]";
@ -439,13 +439,13 @@ abstract class PluginBase extends ComponentPluginBase implements ContainerFactor
* {@inheritdoc}
*/
public function globalTokenForm(&$form, FormStateInterface $form_state) {
$token_items = array();
$token_items = [];
foreach ($this->getAvailableGlobalTokens() as $type => $tokens) {
$item = array(
$item = [
'#markup' => $type,
'children' => array(),
);
'children' => [],
];
foreach ($tokens as $name => $info) {
$item['children'][$name] = "[$type:$name]" . ' - ' . $info['name'] . ': ' . $info['description'];
}
@ -453,17 +453,17 @@ abstract class PluginBase extends ComponentPluginBase implements ContainerFactor
$token_items[$type] = $item;
}
$form['global_tokens'] = array(
$form['global_tokens'] = [
'#type' => 'details',
'#title' => $this->t('Available global token replacements'),
);
$form['global_tokens']['list'] = array(
];
$form['global_tokens']['list'] = [
'#theme' => 'item_list',
'#items' => $token_items,
'#attributes' => array(
'class' => array('global-tokens'),
),
);
'#attributes' => [
'class' => ['global-tokens'],
],
];
}
/**
@ -546,7 +546,7 @@ abstract class PluginBase extends ComponentPluginBase implements ContainerFactor
protected function listLanguages($flags = LanguageInterface::STATE_ALL, array $current_values = NULL) {
$manager = \Drupal::languageManager();
$languages = $manager->getLanguages($flags);
$list = array();
$list = [];
// The entity languages should come first, if requested.
if ($flags & PluginBase::INCLUDE_ENTITY) {
@ -582,7 +582,7 @@ abstract class PluginBase extends ComponentPluginBase implements ContainerFactor
$name = $types_info[$id]['name'];
// Surround IDs by '***LANGUAGE_...***', to avoid query collisions.
$id = '***LANGUAGE_' . $id . '***';
$list[$id] = $this->t('@type language selected for page', array('@type' => $name));
$list[$id] = $this->t('@type language selected for page', ['@type' => $name]);
}
}
if (!empty($current_values)) {
@ -592,7 +592,7 @@ abstract class PluginBase extends ComponentPluginBase implements ContainerFactor
// add that option too, so it is not lost. If not among the current
// values, skip displaying it to avoid user confusion.
if (isset($type['name']) && !isset($list[$id]) && in_array($id, $current_values)) {
$list[$id] = $this->t('@type language selected for page', array('@type' => $type['name']));
$list[$id] = $this->t('@type language selected for page', ['@type' => $type['name']]);
}
}
}
@ -619,7 +619,7 @@ abstract class PluginBase extends ComponentPluginBase implements ContainerFactor
* the query substitutions needed for the special language types.
*/
public static function queryLanguageSubstitutions() {
$changes = array();
$changes = [];
$manager = \Drupal::languageManager();
// Handle default language.

View file

@ -4,6 +4,9 @@ namespace Drupal\views\Plugin\views;
use Drupal\Component\Plugin\PluginInspectionInterface;
/**
* @deprecated as of Drupal 8.3.x, will be removed in Drupal 9.0.0
*/
interface PluginInterface extends PluginInspectionInterface {
}

View file

@ -113,7 +113,7 @@ interface ViewsPluginInterface extends PluginInspectionInterface, DerivativeInsp
* @return array
* An array of available token replacement info or tokens, grouped by type.
*/
public function getAvailableGlobalTokens($prepared = FALSE, array $types = array());
public function getAvailableGlobalTokens($prepared = FALSE, array $types = []);
/**
* Flattens the structure of form elements.
@ -141,7 +141,7 @@ interface ViewsPluginInterface extends PluginInspectionInterface, DerivativeInsp
* @return string
* The tokenized string.
*/
public function globalTokenReplace($string = '', array $options = array());
public function globalTokenReplace($string = '', array $options = []);
/**
* Clears a plugin.

View file

@ -62,7 +62,7 @@ abstract class AreaPluginBase extends HandlerBase {
$this->definition['field'] = !empty($this->definition['field']) ? $this->definition['field'] : '';
$label = !empty($this->definition['label']) ? $this->definition['label'] : $this->definition['field'];
$options['admin_label']['default'] = $label;
$options['empty'] = array('default' => FALSE);
$options['empty'] = ['default' => FALSE];
return $options;
}
@ -81,11 +81,11 @@ abstract class AreaPluginBase extends HandlerBase {
parent::buildOptionsForm($form, $form_state);
if ($form_state->get('type') != 'empty') {
$form['empty'] = array(
$form['empty'] = [
'#type' => 'checkbox',
'#title' => $this->t('Display even if view has no result'),
'#default_value' => isset($this->options['empty']) ? $this->options['empty'] : 0,
);
];
}
}

View file

@ -19,7 +19,7 @@ class Broken extends AreaPluginBase {
*/
public function render($empty = FALSE) {
// Simply render nothing by returning an empty render array.
return array();
return [];
}
}

View file

@ -93,12 +93,12 @@ class Entity extends TokenizeAreaPluginBase {
public function buildOptionsForm(&$form, FormStateInterface $form_state) {
parent::buildOptionsForm($form, $form_state);
$form['view_mode'] = array(
$form['view_mode'] = [
'#type' => 'select',
'#options' => $this->entityManager->getViewModeOptions($this->entityType),
'#title' => $this->t('View mode'),
'#default_value' => $this->options['view_mode'],
);
];
$label = $this->entityManager->getDefinition($this->entityType)->getLabel();
$target = $this->options['target'];
@ -121,12 +121,12 @@ class Entity extends TokenizeAreaPluginBase {
'#default_value' => $target,
];
$form['bypass_access'] = array(
$form['bypass_access'] = [
'#type' => 'checkbox',
'#title' => $this->t('Bypass access checks'),
'#description' => $this->t('If enabled, access permissions for rendering the entity are not checked.'),
'#default_value' => !empty($this->options['bypass_access']),
);
];
}
/**

View file

@ -20,7 +20,7 @@ class HTTPStatusCode extends AreaPluginBase {
protected function defineOptions() {
$options = parent::defineOptions();
$options['status_code'] = array('default' => 200);
$options['status_code'] = ['default' => 200];
return $options;
}
@ -35,29 +35,29 @@ class HTTPStatusCode extends AreaPluginBase {
$options = Response::$statusTexts;
// Move 403/404/500 to the top.
$options = array(
$options = [
'404' => $options['404'],
'403' => $options['403'],
'500' => $options['500'],
) + $options;
] + $options;
// Add the HTTP status code, so it's easier for people to find it.
array_walk($options, function($title, $code) use(&$options) {
$options[$code] = $this->t('@code (@title)', array('@code' => $code, '@title' => $title));
$options[$code] = $this->t('@code (@title)', ['@code' => $code, '@title' => $title]);
});
$form['status_code'] = array(
$form['status_code'] = [
'#title' => $this->t('HTTP status code'),
'#type' => 'select',
'#default_value' => $this->options['status_code'],
'#options' => $options,
);
];
}
/**
* {@inheritdoc}
*/
function render($empty = FALSE) {
public function render($empty = FALSE) {
if (!$empty || !empty($this->options['empty'])) {
$build['#attached']['http_header'][] = ['Status', $this->options['status_code']];
return $build;

View file

@ -26,11 +26,11 @@ class Messages extends AreaPluginBase {
*/
public function render($empty = FALSE) {
if (!$empty || !empty($this->options['empty'])) {
return array(
return [
'#type' => 'status_messages',
);
];
}
return array();
return [];
}
}

View file

@ -22,9 +22,9 @@ class Result extends AreaPluginBase {
protected function defineOptions() {
$options = parent::defineOptions();
$options['content'] = array(
$options['content'] = [
'default' => $this->t('Displaying @start - @end of @total'),
);
];
return $options;
}
@ -34,9 +34,9 @@ class Result extends AreaPluginBase {
*/
public function buildOptionsForm(&$form, FormStateInterface $form_state) {
parent::buildOptionsForm($form, $form_state);
$item_list = array(
$item_list = [
'#theme' => 'item_list',
'#items' => array(
'#items' => [
'@start -- the initial record number in the set',
'@end -- the last record number in the set',
'@total -- the total records in the set',
@ -45,16 +45,16 @@ class Result extends AreaPluginBase {
'@current_page -- the current page number',
'@current_record_count -- the current page record count',
'@page_count -- the total page count',
),
);
],
];
$list = drupal_render($item_list);
$form['content'] = array(
$form['content'] = [
'#title' => $this->t('Display'),
'#type' => 'textarea',
'#rows' => 3,
'#default_value' => $this->options['content'],
'#description' => $this->t('You may use HTML code in this field. The following tokens are supported:') . $list,
);
];
}
/**
@ -72,7 +72,7 @@ class Result extends AreaPluginBase {
public function render($empty = FALSE) {
// Must have options and does not work on summaries.
if (!isset($this->options['content']) || $this->view->style_plugin instanceof DefaultSummary) {
return array();
return [];
}
$output = '';
$format = $this->options['content'];
@ -113,9 +113,9 @@ class Result extends AreaPluginBase {
$output .= Xss::filterAdmin(str_replace(array_keys($replacements), array_values($replacements), $format));
}
// Return as render array.
return array(
return [
'#markup' => $output,
);
];
}
}

View file

@ -18,12 +18,12 @@ class Text extends TokenizeAreaPluginBase {
*/
protected function defineOptions() {
$options = parent::defineOptions();
$options['content'] = array(
'contains' => array(
'value' => array('default' => ''),
'format' => array('default' => NULL),
),
);
$options['content'] = [
'contains' => [
'value' => ['default' => ''],
'format' => ['default' => NULL],
],
];
return $options;
}
@ -33,14 +33,25 @@ class Text extends TokenizeAreaPluginBase {
public function buildOptionsForm(&$form, FormStateInterface $form_state) {
parent::buildOptionsForm($form, $form_state);
$form['content'] = array(
$form['content'] = [
'#title' => $this->t('Content'),
'#type' => 'text_format',
'#default_value' => $this->options['content']['value'],
'#rows' => 6,
'#format' => isset($this->options['content']['format']) ? $this->options['content']['format'] : filter_default_format(),
'#editor' => FALSE,
);
];
}
/**
* {@inheritdoc}
*/
public function preQuery() {
$content = $this->options['content']['value'];
// Check for tokens that require a total row count.
if (strpos($content, '[view:page-count]') !== FALSE || strpos($content, '[view:total-rows]') !== FALSE) {
$this->view->get_total_rows = TRUE;
}
}
/**
@ -49,14 +60,14 @@ class Text extends TokenizeAreaPluginBase {
public function render($empty = FALSE) {
$format = isset($this->options['content']['format']) ? $this->options['content']['format'] : filter_default_format();
if (!$empty || !empty($this->options['empty'])) {
return array(
return [
'#type' => 'processed_text',
'#text' => $this->tokenizeValue($this->options['content']['value']),
'#format' => $format,
);
];
}
return array();
return [];
}
}

View file

@ -18,7 +18,7 @@ class TextCustom extends TokenizeAreaPluginBase {
*/
protected function defineOptions() {
$options = parent::defineOptions();
$options['content'] = array('default' => '');
$options['content'] = ['default' => ''];
return $options;
}
@ -28,12 +28,12 @@ class TextCustom extends TokenizeAreaPluginBase {
public function buildOptionsForm(&$form, FormStateInterface $form_state) {
parent::buildOptionsForm($form, $form_state);
$form['content'] = array(
$form['content'] = [
'#title' => $this->t('Content'),
'#type' => 'textarea',
'#default_value' => $this->options['content'],
'#rows' => 6,
);
];
}
/**
@ -41,12 +41,12 @@ class TextCustom extends TokenizeAreaPluginBase {
*/
public function render($empty = FALSE) {
if (!$empty || !empty($this->options['empty'])) {
return array(
return [
'#markup' => $this->renderTextarea($this->options['content']),
);
];
}
return array();
return [];
}
/**

View file

@ -18,7 +18,7 @@ class Title extends AreaPluginBase {
*/
protected function defineOptions() {
$options = parent::defineOptions();
$options['title'] = array('default' => '');
$options['title'] = ['default' => ''];
return $options;
}
@ -28,12 +28,12 @@ class Title extends AreaPluginBase {
public function buildOptionsForm(&$form, FormStateInterface $form_state) {
parent::buildOptionsForm($form, $form_state);
$form['title'] = array(
$form['title'] = [
'#type' => 'textfield',
'#title' => $this->t('Overridden title'),
'#default_value' => $this->options['title'],
'#description' => $this->t('Override the title of this view when it is empty. The available global tokens below can be used here.'),
);
];
// Don't use the AreaPluginBase tokenForm method, we don't want row tokens.
$this->globalTokenForm($form, $form_state);
@ -57,7 +57,7 @@ class Title extends AreaPluginBase {
*/
public function render($empty = FALSE) {
// Do nothing for this handler by returning an empty render array.
return array();
return [];
}
}

View file

@ -21,7 +21,7 @@ abstract class TokenizeAreaPluginBase extends AreaPluginBase {
*/
protected function defineOptions() {
$options = parent::defineOptions();
$options['tokenize'] = array('default' => FALSE);
$options['tokenize'] = ['default' => FALSE];
return $options;
}
@ -39,14 +39,14 @@ abstract class TokenizeAreaPluginBase extends AreaPluginBase {
* Adds tokenization form elements.
*/
public function tokenForm(&$form, FormStateInterface $form_state) {
$form['tokenize'] = array(
$form['tokenize'] = [
'#type' => 'checkbox',
'#title' => $this->t('Use replacement tokens from the first row'),
'#default_value' => $this->options['tokenize'],
);
];
// Get a list of the available fields and arguments for token replacement.
$options = array();
$options = [];
$optgroup_arguments = (string) t('Arguments');
$optgroup_fields = (string) t('Fields');
foreach ($this->view->display_handler->getHandlers('field') as $field => $handler) {
@ -54,35 +54,35 @@ abstract class TokenizeAreaPluginBase extends AreaPluginBase {
}
foreach ($this->view->display_handler->getHandlers('argument') as $arg => $handler) {
$options[$optgroup_arguments]["{{ arguments.$arg }}"] = $this->t('@argument title', array('@argument' => $handler->adminLabel()));
$options[$optgroup_arguments]["{{ raw_arguments.$arg }}"] = $this->t('@argument input', array('@argument' => $handler->adminLabel()));
$options[$optgroup_arguments]["{{ arguments.$arg }}"] = $this->t('@argument title', ['@argument' => $handler->adminLabel()]);
$options[$optgroup_arguments]["{{ raw_arguments.$arg }}"] = $this->t('@argument input', ['@argument' => $handler->adminLabel()]);
}
if (!empty($options)) {
$form['tokens'] = array(
$form['tokens'] = [
'#type' => 'details',
'#title' => $this->t('Replacement patterns'),
'#open' => TRUE,
'#id' => 'edit-options-token-help',
'#states' => array(
'visible' => array(
':input[name="options[tokenize]"]' => array('checked' => TRUE),
),
),
);
$form['tokens']['help'] = array(
'#states' => [
'visible' => [
':input[name="options[tokenize]"]' => ['checked' => TRUE],
],
],
];
$form['tokens']['help'] = [
'#markup' => '<p>' . $this->t('The following tokens are available. You may use Twig syntax in this field.') . '</p>',
);
];
foreach (array_keys($options) as $type) {
if (!empty($options[$type])) {
$items = array();
$items = [];
foreach ($options[$type] as $key => $value) {
$items[] = $key . ' == ' . $value;
}
$form['tokens'][$type]['tokens'] = array(
$form['tokens'][$type]['tokens'] = [
'#theme' => 'item_list',
'#items' => $items,
);
];
}
}
}

View file

@ -66,8 +66,8 @@ class View extends AreaPluginBase {
protected function defineOptions() {
$options = parent::defineOptions();
$options['view_to_insert'] = array('default' => '');
$options['inherit_arguments'] = array('default' => FALSE);
$options['view_to_insert'] = ['default' => ''];
$options['inherit_arguments'] = ['default' => FALSE];
return $options;
}
@ -79,22 +79,22 @@ class View extends AreaPluginBase {
$view_display = $this->view->storage->id() . ':' . $this->view->current_display;
$options = array('' => $this->t('-Select-'));
$options = ['' => $this->t('-Select-')];
$options += Views::getViewsAsOptions(FALSE, 'all', $view_display, FALSE, TRUE);
$form['view_to_insert'] = array(
$form['view_to_insert'] = [
'#type' => 'select',
'#title' => $this->t('View to insert'),
'#default_value' => $this->options['view_to_insert'],
'#description' => $this->t('The view to insert into this area.'),
'#options' => $options,
);
];
$form['inherit_arguments'] = array(
$form['inherit_arguments'] = [
'#type' => 'checkbox',
'#title' => $this->t('Inherit contextual filters'),
'#default_value' => $this->options['inherit_arguments'],
'#description' => $this->t('If checked, this view will receive the same contextual filters as its parent.'),
);
];
}
/**
@ -107,7 +107,7 @@ class View extends AreaPluginBase {
$view = $this->viewStorage->load($view_name)->getExecutable();
if (empty($view) || !$view->access($display_id)) {
return array();
return [];
}
$view->setDisplay($display_id);
@ -118,7 +118,7 @@ class View extends AreaPluginBase {
// Check if the view is part of the parent views of this view
$search = "$view_name:$display_id";
if (in_array($search, $this->view->parent_views)) {
drupal_set_message(t("Recursion detected in view @view display @display.", array('@view' => $view_name, '@display' => $display_id)), 'error');
drupal_set_message(t("Recursion detected in view @view display @display.", ['@view' => $view_name, '@display' => $display_id]), 'error');
}
else {
if (!empty($this->options['inherit_arguments']) && !empty($this->view->args)) {
@ -131,7 +131,7 @@ class View extends AreaPluginBase {
return $output;
}
}
return array();
return [];
}
/**

View file

@ -105,7 +105,7 @@ abstract class ArgumentPluginBase extends HandlerBase implements CacheableDepend
/**
* Determine if the argument needs a style plugin.
*
* @return TRUE/FALSE
* @return bool
*/
public function needsStylePlugin() {
$info = $this->defaultActions($this->options['default_action']);
@ -116,35 +116,35 @@ abstract class ArgumentPluginBase extends HandlerBase implements CacheableDepend
protected function defineOptions() {
$options = parent::defineOptions();
$options['default_action'] = array('default' => 'ignore');
$options['exception'] = array(
'contains' => array(
'value' => array('default' => 'all'),
'title_enable' => array('default' => FALSE),
'title' => array('default' => 'All'),
),
);
$options['title_enable'] = array('default' => FALSE);
$options['title'] = array('default' => '');
$options['default_argument_type'] = array('default' => 'fixed');
$options['default_argument_options'] = array('default' => array());
$options['default_argument_skip_url'] = array('default' => FALSE);
$options['summary_options'] = array('default' => array());
$options['summary'] = array(
'contains' => array(
'sort_order' => array('default' => 'asc'),
'number_of_records' => array('default' => 0),
'format' => array('default' => 'default_summary'),
),
);
$options['specify_validation'] = array('default' => FALSE);
$options['validate'] = array(
'contains' => array(
'type' => array('default' => 'none'),
'fail' => array('default' => 'not found'),
),
);
$options['validate_options'] = array('default' => array());
$options['default_action'] = ['default' => 'ignore'];
$options['exception'] = [
'contains' => [
'value' => ['default' => 'all'],
'title_enable' => ['default' => FALSE],
'title' => ['default' => 'All'],
],
];
$options['title_enable'] = ['default' => FALSE];
$options['title'] = ['default' => ''];
$options['default_argument_type'] = ['default' => 'fixed'];
$options['default_argument_options'] = ['default' => []];
$options['default_argument_skip_url'] = ['default' => FALSE];
$options['summary_options'] = ['default' => []];
$options['summary'] = [
'contains' => [
'sort_order' => ['default' => 'asc'],
'number_of_records' => ['default' => 0],
'format' => ['default' => 'default_summary'],
],
];
$options['specify_validation'] = ['default' => FALSE];
$options['validate'] = [
'contains' => [
'type' => ['default' => 'none'],
'fail' => ['default' => 'not found'],
],
];
$options['validate_options'] = ['default' => []];
return $options;
}
@ -154,68 +154,68 @@ abstract class ArgumentPluginBase extends HandlerBase implements CacheableDepend
$argument_text = $this->view->display_handler->getArgumentText();
$form['#pre_render'][] = array(get_class($this), 'preRenderMoveArgumentOptions');
$form['#pre_render'][] = [get_class($this), 'preRenderMoveArgumentOptions'];
$form['description'] = array(
$form['description'] = [
'#markup' => $argument_text['description'],
'#theme_wrappers' => array('container'),
'#attributes' => array('class' => array('description')),
);
'#theme_wrappers' => ['container'],
'#attributes' => ['class' => ['description']],
];
$form['no_argument'] = array(
$form['no_argument'] = [
'#type' => 'details',
'#title' => $argument_text['filter value not present'],
'#open' => TRUE,
);
];
// Everything in the details is floated, so the last element needs to
// clear those floats.
$form['no_argument']['clearfix'] = array(
$form['no_argument']['clearfix'] = [
'#weight' => 1000,
'#markup' => '<div class="clearfix"></div>',
);
$form['default_action'] = array(
];
$form['default_action'] = [
'#title' => $this->t('Default actions'),
'#title_display' => 'invisible',
'#type' => 'radios',
'#process' => array(array($this, 'processContainerRadios')),
'#process' => [[$this, 'processContainerRadios']],
'#default_value' => $this->options['default_action'],
'#fieldset' => 'no_argument',
);
];
$form['exception'] = array(
$form['exception'] = [
'#type' => 'details',
'#title' => $this->t('Exceptions'),
'#fieldset' => 'no_argument',
);
$form['exception']['value'] = array(
];
$form['exception']['value'] = [
'#type' => 'textfield',
'#title' => $this->t('Exception value'),
'#size' => 20,
'#default_value' => $this->options['exception']['value'],
'#description' => $this->t('If this value is received, the filter will be ignored; i.e, "all values"'),
);
$form['exception']['title_enable'] = array(
];
$form['exception']['title_enable'] = [
'#type' => 'checkbox',
'#title' => $this->t('Override title'),
'#default_value' => $this->options['exception']['title_enable'],
);
$form['exception']['title'] = array(
];
$form['exception']['title'] = [
'#type' => 'textfield',
'#title' => $this->t('Override title'),
'#title_display' => 'invisible',
'#size' => 20,
'#default_value' => $this->options['exception']['title'],
'#description' => $this->t('Override the view and other argument titles. You may use Twig syntax in this field as well as the "arguments" and "raw_arguments" arrays.'),
'#states' => array(
'visible' => array(
':input[name="options[exception][title_enable]"]' => array('checked' => TRUE),
),
),
);
'#states' => [
'visible' => [
':input[name="options[exception][title_enable]"]' => ['checked' => TRUE],
],
],
];
$options = array();
$options = [];
$defaults = $this->defaultActions();
$validate_options = array();
$validate_options = [];
foreach ($defaults as $id => $info) {
$options[$id] = $info['title'];
if (empty($info['default only'])) {
@ -227,30 +227,30 @@ abstract class ArgumentPluginBase extends HandlerBase implements CacheableDepend
}
$form['default_action']['#options'] = $options;
$form['argument_present'] = array(
$form['argument_present'] = [
'#type' => 'details',
'#title' => $argument_text['filter value present'],
'#open' => TRUE,
);
$form['title_enable'] = array(
];
$form['title_enable'] = [
'#type' => 'checkbox',
'#title' => $this->t('Override title'),
'#default_value' => $this->options['title_enable'],
'#fieldset' => 'argument_present',
);
$form['title'] = array(
];
$form['title'] = [
'#type' => 'textfield',
'#title' => $this->t('Provide title'),
'#title_display' => 'invisible',
'#default_value' => $this->options['title'],
'#description' => $this->t('Override the view and other argument titles. You may use Twig syntax in this field.'),
'#states' => array(
'visible' => array(
':input[name="options[title_enable]"]' => array('checked' => TRUE),
),
),
'#states' => [
'visible' => [
':input[name="options[title_enable]"]' => ['checked' => TRUE],
],
],
'#fieldset' => 'argument_present',
);
];
$output = $this->getTokenHelp();
$form['token_help'] = [
@ -269,29 +269,29 @@ abstract class ArgumentPluginBase extends HandlerBase implements CacheableDepend
],
];
$form['specify_validation'] = array(
$form['specify_validation'] = [
'#type' => 'checkbox',
'#title' => $this->t('Specify validation criteria'),
'#default_value' => $this->options['specify_validation'],
'#fieldset' => 'argument_present',
);
];
$form['validate'] = array(
$form['validate'] = [
'#type' => 'container',
'#fieldset' => 'argument_present',
);
];
// Validator options include derivatives with :. These are sanitized for js
// and reverted on submission.
$form['validate']['type'] = array(
$form['validate']['type'] = [
'#type' => 'select',
'#title' => $this->t('Validator'),
'#default_value' => static::encodeValidatorId($this->options['validate']['type']),
'#states' => array(
'visible' => array(
':input[name="options[specify_validation]"]' => array('checked' => TRUE),
),
),
);
'#states' => [
'visible' => [
':input[name="options[specify_validation]"]' => ['checked' => TRUE],
],
],
];
$plugins = Views::pluginManager('argument_validator')->getDefinitions();
foreach ($plugins as $id => $info) {
@ -320,21 +320,21 @@ abstract class ArgumentPluginBase extends HandlerBase implements CacheableDepend
if ($plugin->access() || $this->options['validate']['type'] == $id) {
// Sanitize ID for js.
$sanitized_id = static::encodeValidatorId($id);
$form['validate']['options'][$sanitized_id] = array(
$form['validate']['options'][$sanitized_id] = [
'#prefix' => '<div id="edit-options-validate-options-' . $sanitized_id . '-wrapper">',
'#suffix' => '</div>',
'#type' => 'item',
// Even if the plugin has no options add the key to the form_state.
'#input' => TRUE, // trick it into checking input to make #process run
'#states' => array(
'visible' => array(
':input[name="options[specify_validation]"]' => array('checked' => TRUE),
':input[name="options[validate][type]"]' => array('value' => $sanitized_id),
),
),
'#states' => [
'visible' => [
':input[name="options[specify_validation]"]' => ['checked' => TRUE],
':input[name="options[validate][type]"]' => ['value' => $sanitized_id],
],
],
'#id' => 'edit-options-validate-options-' . $sanitized_id,
'#default_value' => array(),
);
'#default_value' => [],
];
$plugin->buildOptionsForm($form['validate']['options'][$sanitized_id], $form_state);
$validate_types[$sanitized_id] = $info['title'];
}
@ -345,18 +345,18 @@ abstract class ArgumentPluginBase extends HandlerBase implements CacheableDepend
asort($validate_types);
$form['validate']['type']['#options'] = $validate_types;
$form['validate']['fail'] = array(
$form['validate']['fail'] = [
'#type' => 'select',
'#title' => $this->t('Action to take if filter value does not validate'),
'#default_value' => $this->options['validate']['fail'],
'#options' => $validate_options,
'#states' => array(
'visible' => array(
':input[name="options[specify_validation]"]' => array('checked' => TRUE),
),
),
'#states' => [
'visible' => [
':input[name="options[specify_validation]"]' => ['checked' => TRUE],
],
],
'#fieldset' => 'argument_present',
);
];
}
/**
@ -370,8 +370,8 @@ abstract class ArgumentPluginBase extends HandlerBase implements CacheableDepend
foreach ($this->view->display_handler->getHandlers('argument') as $arg => $handler) {
/** @var \Drupal\views\Plugin\views\argument\ArgumentPluginBase $handler */
$options[(string) t('Arguments')]["{{ arguments.$arg }}"] = $this->t('@argument title', array('@argument' => $handler->adminLabel()));
$options[(string) t('Arguments')]["{{ raw_arguments.$arg }}"] = $this->t('@argument input', array('@argument' => $handler->adminLabel()));
$options[(string) t('Arguments')]["{{ arguments.$arg }}"] = $this->t('@argument title', ['@argument' => $handler->adminLabel()]);
$options[(string) t('Arguments')]["{{ raw_arguments.$arg }}"] = $this->t('@argument input', ['@argument' => $handler->adminLabel()]);
}
// We have some options, so make a list.
@ -381,14 +381,14 @@ abstract class ArgumentPluginBase extends HandlerBase implements CacheableDepend
];
foreach (array_keys($options) as $type) {
if (!empty($options[$type])) {
$items = array();
$items = [];
foreach ($options[$type] as $key => $value) {
$items[] = $key . ' == ' . $value;
}
$item_list = array(
$item_list = [
'#theme' => 'item_list',
'#items' => $items,
);
];
$output[] = $item_list;
}
}
@ -488,38 +488,38 @@ abstract class ArgumentPluginBase extends HandlerBase implements CacheableDepend
* Override this method to provide additional (or fewer) default behaviors.
*/
protected function defaultActions($which = NULL) {
$defaults = array(
'ignore' => array(
$defaults = [
'ignore' => [
'title' => $this->t('Display all results for the specified field'),
'method' => 'defaultIgnore',
),
'default' => array(
],
'default' => [
'title' => $this->t('Provide default value'),
'method' => 'defaultDefault',
'form method' => 'defaultArgumentForm',
'has default argument' => TRUE,
'default only' => TRUE, // this can only be used for missing argument, not validation failure
),
'not found' => array(
],
'not found' => [
'title' => $this->t('Hide view'),
'method' => 'defaultNotFound',
'hard fail' => TRUE, // This is a hard fail condition
),
'summary' => array(
],
'summary' => [
'title' => $this->t('Display a summary'),
'method' => 'defaultSummary',
'form method' => 'defaultSummaryForm',
'style plugin' => TRUE,
),
'empty' => array(
],
'empty' => [
'title' => $this->t('Display contents of "No results found"'),
'method' => 'defaultEmpty',
),
'access denied' => array(
],
'access denied' => [
'title' => $this->t('Display "Access Denied"'),
'method' => 'defaultAccessDenied',
),
);
],
];
if ($this->view->display_handler->hasPath()) {
$defaults['not found']['title'] = $this->t('Show "Page not found"');
@ -541,31 +541,31 @@ abstract class ArgumentPluginBase extends HandlerBase implements CacheableDepend
*/
public function defaultArgumentForm(&$form, FormStateInterface $form_state) {
$plugins = Views::pluginManager('argument_default')->getDefinitions();
$options = array();
$options = [];
$form['default_argument_skip_url'] = array(
$form['default_argument_skip_url'] = [
'#type' => 'checkbox',
'#title' => $this->t('Skip default argument for view URL'),
'#default_value' => $this->options['default_argument_skip_url'],
'#description' => $this->t('Select whether to include this default argument when constructing the URL for this view. Skipping default arguments is useful e.g. in the case of feeds.')
);
];
$form['default_argument_type'] = array(
$form['default_argument_type'] = [
'#prefix' => '<div id="edit-options-default-argument-type-wrapper">',
'#suffix' => '</div>',
'#type' => 'select',
'#id' => 'edit-options-default-argument-type',
'#title' => $this->t('Type'),
'#default_value' => $this->options['default_argument_type'],
'#states' => array(
'visible' => array(
':input[name="options[default_action]"]' => array('value' => 'default'),
),
),
'#states' => [
'visible' => [
':input[name="options[default_action]"]' => ['value' => 'default'],
],
],
// Views custom key, moves this element to the appropriate container
// under the radio button.
'#argument_option' => 'default',
);
];
foreach ($plugins as $id => $info) {
if (!empty($info['no_ui'])) {
@ -575,21 +575,21 @@ abstract class ArgumentPluginBase extends HandlerBase implements CacheableDepend
if ($plugin) {
if ($plugin->access() || $this->options['default_argument_type'] == $id) {
$form['argument_default']['#argument_option'] = 'default';
$form['argument_default'][$id] = array(
$form['argument_default'][$id] = [
'#prefix' => '<div id="edit-options-argument-default-options-' . $id . '-wrapper">',
'#suffix' => '</div>',
'#id' => 'edit-options-argument-default-options-' . $id,
'#type' => 'item',
// Even if the plugin has no options add the key to the form_state.
'#input' => TRUE,
'#states' => array(
'visible' => array(
':input[name="options[default_action]"]' => array('value' => 'default'),
':input[name="options[default_argument_type]"]' => array('value' => $id),
),
),
'#default_value' => array(),
);
'#states' => [
'visible' => [
':input[name="options[default_action]"]' => ['value' => 'default'],
':input[name="options[default_argument_type]"]' => ['value' => $id],
],
],
'#default_value' => [],
];
$options[$id] = $info['title'];
$plugin->buildOptionsForm($form['argument_default'][$id], $form_state);
}
@ -606,8 +606,8 @@ abstract class ArgumentPluginBase extends HandlerBase implements CacheableDepend
*/
public function defaultSummaryForm(&$form, FormStateInterface $form_state) {
$style_plugins = Views::pluginManager('style')->getDefinitions();
$summary_plugins = array();
$format_options = array();
$summary_plugins = [];
$format_options = [];
foreach ($style_plugins as $key => $plugin) {
if (isset($plugin['display_types']) && in_array('summary', $plugin['display_types'])) {
$summary_plugins[$key] = $plugin;
@ -615,48 +615,48 @@ abstract class ArgumentPluginBase extends HandlerBase implements CacheableDepend
}
}
$form['summary'] = array(
$form['summary'] = [
// Views custom key, moves this element to the appropriate container
// under the radio button.
'#argument_option' => 'summary',
);
$form['summary']['sort_order'] = array(
];
$form['summary']['sort_order'] = [
'#type' => 'radios',
'#title' => $this->t('Sort order'),
'#options' => array('asc' => $this->t('Ascending'), 'desc' => $this->t('Descending')),
'#options' => ['asc' => $this->t('Ascending'), 'desc' => $this->t('Descending')],
'#default_value' => $this->options['summary']['sort_order'],
'#states' => array(
'visible' => array(
':input[name="options[default_action]"]' => array('value' => 'summary'),
),
),
);
$form['summary']['number_of_records'] = array(
'#states' => [
'visible' => [
':input[name="options[default_action]"]' => ['value' => 'summary'],
],
],
];
$form['summary']['number_of_records'] = [
'#type' => 'radios',
'#title' => $this->t('Sort by'),
'#default_value' => $this->options['summary']['number_of_records'],
'#options' => array(
'#options' => [
0 => $this->getSortName(),
1 => $this->t('Number of records')
),
'#states' => array(
'visible' => array(
':input[name="options[default_action]"]' => array('value' => 'summary'),
),
),
);
],
'#states' => [
'visible' => [
':input[name="options[default_action]"]' => ['value' => 'summary'],
],
],
];
$form['summary']['format'] = array(
$form['summary']['format'] = [
'#type' => 'radios',
'#title' => $this->t('Format'),
'#options' => $format_options,
'#default_value' => $this->options['summary']['format'],
'#states' => array(
'visible' => array(
':input[name="options[default_action]"]' => array('value' => 'summary'),
),
),
);
'#states' => [
'visible' => [
':input[name="options[default_action]"]' => ['value' => 'summary'],
],
],
];
foreach ($summary_plugins as $id => $info) {
$plugin = $this->getPlugin('style', $id);
@ -664,20 +664,20 @@ abstract class ArgumentPluginBase extends HandlerBase implements CacheableDepend
continue;
}
if ($plugin) {
$form['summary']['options'][$id] = array(
$form['summary']['options'][$id] = [
'#prefix' => '<div id="edit-options-summary-options-' . $id . '-wrapper">',
'#suffix' => '</div>',
'#id' => 'edit-options-summary-options-' . $id,
'#type' => 'item',
'#input' => TRUE, // trick it into checking input to make #process run
'#states' => array(
'visible' => array(
':input[name="options[default_action]"]' => array('value' => 'summary'),
':input[name="options[summary][format]"]' => array('value' => $id),
),
),
'#default_value' => array(),
);
'#states' => [
'visible' => [
':input[name="options[default_action]"]' => ['value' => 'summary'],
':input[name="options[summary][format]"]' => ['value' => $id],
],
],
'#default_value' => [],
];
$options[$id] = $info['title'];
$plugin->buildOptionsForm($form['summary']['options'][$id], $form_state);
}
@ -703,7 +703,7 @@ abstract class ArgumentPluginBase extends HandlerBase implements CacheableDepend
}
if (!empty($info['method args'])) {
return call_user_func_array(array(&$this, $info['method']), $info['method args']);
return call_user_func_array([&$this, $info['method']], $info['method args']);
}
else {
return $this->{$info['method']}();
@ -760,7 +760,7 @@ abstract class ArgumentPluginBase extends HandlerBase implements CacheableDepend
// We return with no query; this will force the empty text.
$this->view->built = TRUE;
$this->view->executed = TRUE;
$this->view->result = array();
$this->view->result = [];
return FALSE;
}
@ -775,7 +775,7 @@ abstract class ArgumentPluginBase extends HandlerBase implements CacheableDepend
/**
* Determine if the argument is set to provide a default argument.
*/
function hasDefaultArgument() {
public function hasDefaultArgument() {
$info = $this->defaultActions($this->options['default_action']);
return !empty($info['has default argument']);
}
@ -897,7 +897,7 @@ abstract class ArgumentPluginBase extends HandlerBase implements CacheableDepend
// Add the number of nodes counter
$distinct = ($this->view->display_handler->getOption('distinct') && empty($this->query->no_distinct));
$count_alias = $this->query->addField($this->view->storage->get('base_table'), $this->view->storage->get('base_field'), 'num_records', array('count' => TRUE, 'distinct' => $distinct));
$count_alias = $this->query->addField($this->view->storage->get('base_table'), $this->view->storage->get('base_field'), 'num_records', ['count' => TRUE, 'distinct' => $distinct]);
$this->query->addGroupBy($this->name_alias);
if ($count_field) {
@ -960,7 +960,7 @@ abstract class ArgumentPluginBase extends HandlerBase implements CacheableDepend
*
* This usually needs to be overridden to provide a proper title.
*/
function title() {
public function title() {
return $this->argument;
}
@ -1074,7 +1074,7 @@ abstract class ArgumentPluginBase extends HandlerBase implements CacheableDepend
* Get the display or row plugin, if it exists.
*/
public function getPlugin($type = 'argument_default', $name = NULL) {
$options = array();
$options = [];
switch ($type) {
case 'argument_default':
if (!isset($this->options['default_argument_type'])) {
@ -1127,7 +1127,7 @@ abstract class ArgumentPluginBase extends HandlerBase implements CacheableDepend
* their argument is (e.g. alphabetical, numeric, date).
*/
public function getSortName() {
return $this->t('Default sort', array(), array('context' => 'Sort order'));
return $this->t('Default sort', [], ['context' => 'Sort order']);
}
/**
@ -1142,12 +1142,12 @@ abstract class ArgumentPluginBase extends HandlerBase implements CacheableDepend
public static function processContainerRadios($element) {
if (count($element['#options']) > 0) {
foreach ($element['#options'] as $key => $choice) {
$element += array($key => array());
$element += [$key => []];
// Generate the parents as the autogenerator does, so we will have a
// unique id for each radio button.
$parents_for_id = array_merge($element['#parents'], array($key));
$parents_for_id = array_merge($element['#parents'], [$key]);
$element[$key] += array(
$element[$key] += [
'#type' => 'radio',
'#title' => $choice,
// The key is sanitized in drupal_attributes() during output from the
@ -1158,11 +1158,11 @@ abstract class ArgumentPluginBase extends HandlerBase implements CacheableDepend
'#parents' => $element['#parents'],
'#id' => Html::getUniqueId('edit-' . implode('-', $parents_for_id)),
'#ajax' => isset($element['#ajax']) ? $element['#ajax'] : NULL,
);
$element[$key . '_options'] = array(
];
$element[$key . '_options'] = [
'#type' => 'container',
'#attributes' => array('class' => array('views-admin-dependent')),
);
'#attributes' => ['class' => ['views-admin-dependent']],
];
}
}
return $element;
@ -1326,6 +1326,17 @@ abstract class ArgumentPluginBase extends HandlerBase implements CacheableDepend
return $dependencies;
}
/**
* Returns a context definition for this argument.
*
* @return \Drupal\Core\Plugin\Context\ContextDefinitionInterface|null
* A context definition that represents the argument or NULL if that is
* not possible.
*/
public function getContextDefinition() {
return $this->getPlugin('argument_validator')->getContextDefinition();
}
}
/**

View file

@ -85,9 +85,9 @@ class Date extends Formula implements ContainerFactoryPluginInterface {
*/
public function defaultArgumentForm(&$form, FormStateInterface $form_state) {
parent::defaultArgumentForm($form, $form_state);
$form['default_argument_type']['#options'] += array('date' => $this->t('Current date'));
$form['default_argument_type']['#options'] += array('node_created' => $this->t("Current node's creation time"));
$form['default_argument_type']['#options'] += array('node_changed' => $this->t("Current node's update time"));
$form['default_argument_type']['#options'] += ['date' => $this->t('Current date')];
$form['default_argument_type']['#options'] += ['node_created' => $this->t("Current node's creation time")];
$form['default_argument_type']['#options'] += ['node_changed' => $this->t("Current node's update time")];
}
/**
@ -98,7 +98,7 @@ class Date extends Formula implements ContainerFactoryPluginInterface {
if (!$raw && $this->options['default_argument_type'] == 'date') {
return date($this->argFormat, REQUEST_TIME);
}
elseif (!$raw && in_array($this->options['default_argument_type'], array('node_created', 'node_changed'))) {
elseif (!$raw && in_array($this->options['default_argument_type'], ['node_created', 'node_changed'])) {
$node = $this->routeMatch->getParameter('node');
if (!($node instanceof NodeInterface)) {
@ -119,7 +119,7 @@ class Date extends Formula implements ContainerFactoryPluginInterface {
* {@inheritdoc}
*/
public function getSortName() {
return $this->t('Date', array(), array('context' => 'Sort order'));
return $this->t('Date', [], ['context' => 'Sort order']);
}
/**

View file

@ -31,7 +31,7 @@ class DayDate extends Date {
/**
* Provide a link to the next level of the view
*/
function title() {
public function title() {
$day = str_pad($this->argument, 2, '0', STR_PAD_LEFT);
return format_date(strtotime("2005" . "05" . $day . " 00:00:00 UTC"), 'custom', $this->format, 'UTC');
}

View file

@ -59,9 +59,9 @@ class Formula extends ArgumentPluginBase {
// Now that our table is secure, get our formula.
$placeholder = $this->placeholder();
$formula = $this->getFormula() . ' = ' . $placeholder;
$placeholders = array(
$placeholders = [
$placeholder => $this->argument,
);
];
$this->query->addWhere(0, $formula, $placeholders, 'formula');
}

View file

@ -30,7 +30,7 @@ class FullDate extends Date {
/**
* Provide a link to the next level of the view
*/
function title() {
public function title() {
return format_date(strtotime($this->argument . " 00:00:00 UTC"), 'custom', $this->format, 'UTC');
}

View file

@ -16,7 +16,7 @@ class GroupByNumeric extends ArgumentPluginBase {
$field = $this->getField();
$placeholder = $this->placeholder();
$this->query->addHavingExpression(0, "$field = $placeholder", array($placeholder => $this->argument));
$this->query->addHavingExpression(0, "$field = $placeholder", [$placeholder => $this->argument]);
}
public function adminLabel($short = FALSE) {
@ -27,7 +27,7 @@ class GroupByNumeric extends ArgumentPluginBase {
* {@inheritdoc}
*/
public function getSortName() {
return $this->t('Numerical', array(), array('context' => 'Sort order'));
return $this->t('Numerical', [], ['context' => 'Sort order']);
}
}

View file

@ -26,7 +26,7 @@ class LanguageArgument extends ArgumentPluginBase {
* Gets the user friendly version of the language name for display as a
* title placeholder.
*/
function title() {
public function title() {
return $this->language($this->argument);
}
@ -40,7 +40,7 @@ class LanguageArgument extends ArgumentPluginBase {
* The translated name for the language, or "Unknown language" if the
* language was not found.
*/
function language($langcode) {
public function language($langcode) {
$languages = $this->listLanguages();
return isset($languages[$langcode]) ? $languages[$langcode] : $this->t('Unknown language');
}

View file

@ -34,18 +34,18 @@ class ManyToOne extends ArgumentPluginBase {
// Ensure defaults for these, during summaries and stuff:
$this->operator = 'or';
$this->value = array();
$this->value = [];
}
protected function defineOptions() {
$options = parent::defineOptions();
if (!empty($this->definition['numeric'])) {
$options['break_phrase'] = array('default' => FALSE);
$options['break_phrase'] = ['default' => FALSE];
}
$options['add_table'] = array('default' => FALSE);
$options['require_value'] = array('default' => FALSE);
$options['add_table'] = ['default' => FALSE];
$options['require_value'] = ['default' => FALSE];
if (isset($this->helper)) {
$this->helper->defineOptions($options);
@ -62,28 +62,28 @@ class ManyToOne extends ArgumentPluginBase {
parent::buildOptionsForm($form, $form_state);
// allow + for or, , for and
$form['break_phrase'] = array(
$form['break_phrase'] = [
'#type' => 'checkbox',
'#title' => $this->t('Allow multiple values'),
'#description' => $this->t('If selected, users can enter multiple values in the form of 1+2+3 (for OR) or 1,2,3 (for AND).'),
'#default_value' => !empty($this->options['break_phrase']),
'#group' => 'options][more',
);
];
$form['add_table'] = array(
$form['add_table'] = [
'#type' => 'checkbox',
'#title' => $this->t('Allow multiple filter values to work together'),
'#description' => $this->t('If selected, multiple instances of this filter can work together, as though multiple values were supplied to the same filter. This setting is not compatible with the "Reduce duplicates" setting.'),
'#default_value' => !empty($this->options['add_table']),
'#group' => 'options][more',
);
];
$form['require_value'] = array(
$form['require_value'] = [
'#type' => 'checkbox',
'#title' => $this->t('Do not display items with no value in summary'),
'#default_value' => !empty($this->options['require_value']),
'#group' => 'options][more',
);
];
$this->helper->buildOptionsForm($form, $form_state);
}
@ -119,14 +119,14 @@ class ManyToOne extends ArgumentPluginBase {
$this->unpackArgumentValue($force_int);
}
else {
$this->value = array($this->argument);
$this->value = [$this->argument];
$this->operator = 'or';
}
$this->helper->addFilter();
}
function title() {
public function title() {
if (!$this->argument) {
return !empty($this->definition['empty field name']) ? $this->definition['empty field name'] : $this->t('Uncategorized');
}
@ -136,7 +136,7 @@ class ManyToOne extends ArgumentPluginBase {
$this->unpackArgumentValue($force_int);
}
else {
$this->value = array($this->argument);
$this->value = [$this->argument];
$this->operator = 'or';
}
@ -146,7 +146,7 @@ class ManyToOne extends ArgumentPluginBase {
return !empty($this->definition['empty field name']) ? $this->definition['empty field name'] : $this->t('Uncategorized');
}
if ($this->value === array(-1)) {
if ($this->value === [-1]) {
return !empty($this->definition['invalid input']) ? $this->definition['invalid input'] : $this->t('Invalid input');
}

View file

@ -30,7 +30,7 @@ class MonthDate extends Date {
/**
* Provide a link to the next level of the view
*/
function title() {
public function title() {
$month = str_pad($this->argument, 2, '0', STR_PAD_LEFT);
return format_date(strtotime("2005" . $month . "15" . " 00:00:00 UTC"), 'custom', $this->format, 'UTC');
}

View file

@ -15,7 +15,7 @@ class NullArgument extends ArgumentPluginBase {
protected function defineOptions() {
$options = parent::defineOptions();
$options['must_not_be'] = array('default' => FALSE);
$options['must_not_be'] = ['default' => FALSE];
return $options;
}
@ -25,13 +25,13 @@ class NullArgument extends ArgumentPluginBase {
*/
public function buildOptionsForm(&$form, FormStateInterface $form_state) {
parent::buildOptionsForm($form, $form_state);
$form['must_not_be'] = array(
$form['must_not_be'] = [
'#type' => 'checkbox',
'#title' => $this->t('Fail basic validation if any argument is given'),
'#default_value' => !empty($this->options['must_not_be']),
'#description' => $this->t('By checking this field, you can use this to make sure views with more arguments than necessary fail validation.'),
'#group' => 'options][more',
);
];
unset($form['exception']);
}
@ -42,7 +42,7 @@ class NullArgument extends ArgumentPluginBase {
*/
protected function defaultActions($which = NULL) {
if ($which) {
if (in_array($which, array('ignore', 'not found', 'empty', 'default'))) {
if (in_array($which, ['ignore', 'not found', 'empty', 'default'])) {
return parent::defaultActions($which);
}
return;

View file

@ -3,6 +3,7 @@
namespace Drupal\views\Plugin\views\argument;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Plugin\Context\ContextDefinition;
/**
* Basic argument handler for arguments that are numeric. Incorporates
@ -29,8 +30,8 @@ class NumericArgument extends ArgumentPluginBase {
protected function defineOptions() {
$options = parent::defineOptions();
$options['break_phrase'] = array('default' => FALSE);
$options['not'] = array('default' => FALSE);
$options['break_phrase'] = ['default' => FALSE];
$options['not'] = ['default' => FALSE];
return $options;
}
@ -39,24 +40,24 @@ class NumericArgument extends ArgumentPluginBase {
parent::buildOptionsForm($form, $form_state);
// allow + for or, , for and
$form['break_phrase'] = array(
$form['break_phrase'] = [
'#type' => 'checkbox',
'#title' => $this->t('Allow multiple values'),
'#description' => $this->t('If selected, users can enter multiple values in the form of 1+2+3 (for OR) or 1,2,3 (for AND).'),
'#default_value' => !empty($this->options['break_phrase']),
'#group' => 'options][more',
);
];
$form['not'] = array(
$form['not'] = [
'#type' => 'checkbox',
'#title' => $this->t('Exclude'),
'#description' => $this->t('If selected, the numbers entered for the filter will be excluded rather than limiting the view.'),
'#default_value' => !empty($this->options['not']),
'#group' => 'options][more',
);
];
}
function title() {
public function title() {
if (!$this->argument) {
return !empty($this->definition['empty field name']) ? $this->definition['empty field name'] : $this->t('Uncategorized');
}
@ -67,7 +68,7 @@ class NumericArgument extends ArgumentPluginBase {
$this->operator = $break->operator;
}
else {
$this->value = array($this->argument);
$this->value = [$this->argument];
$this->operator = 'or';
}
@ -75,7 +76,7 @@ class NumericArgument extends ArgumentPluginBase {
return !empty($this->definition['empty field name']) ? $this->definition['empty field name'] : $this->t('Uncategorized');
}
if ($this->value === array(-1)) {
if ($this->value === [-1]) {
return !empty($this->definition['invalid input']) ? $this->definition['invalid input'] : $this->t('Invalid input');
}
@ -100,7 +101,7 @@ class NumericArgument extends ArgumentPluginBase {
$this->operator = $break->operator;
}
else {
$this->value = array($this->argument);
$this->value = [$this->argument];
}
$placeholder = $this->placeholder();
@ -109,11 +110,11 @@ class NumericArgument extends ArgumentPluginBase {
if (count($this->value) > 1) {
$operator = empty($this->options['not']) ? 'IN' : 'NOT IN';
$placeholder .= '[]';
$this->query->addWhereExpression(0, "$this->tableAlias.$this->realField $operator($placeholder) $null_check", array($placeholder => $this->value));
$this->query->addWhereExpression(0, "$this->tableAlias.$this->realField $operator($placeholder) $null_check", [$placeholder => $this->value]);
}
else {
$operator = empty($this->options['not']) ? '=' : '!=';
$this->query->addWhereExpression(0, "$this->tableAlias.$this->realField $operator $placeholder $null_check", array($placeholder => $this->argument));
$this->query->addWhereExpression(0, "$this->tableAlias.$this->realField $operator $placeholder $null_check", [$placeholder => $this->argument]);
}
}
@ -121,7 +122,20 @@ class NumericArgument extends ArgumentPluginBase {
* {@inheritdoc}
*/
public function getSortName() {
return $this->t('Numerical', array(), array('context' => 'Sort order'));
return $this->t('Numerical', [], ['context' => 'Sort order']);
}
/**
* {@inheritdoc}
*/
public function getContextDefinition() {
if ($context_definition = parent::getContextDefinition()) {
return $context_definition;
}
// If the parent does not provide a context definition through the
// validation plugin, fall back to the integer type.
return new ContextDefinition('integer', $this->adminLabel(), FALSE);
}
}

View file

@ -5,6 +5,7 @@ namespace Drupal\views\Plugin\views\argument;
use Drupal\Component\Utility\Unicode;
use Drupal\Core\Database\Database;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Plugin\Context\ContextDefinition;
use Drupal\views\ViewExecutable;
use Drupal\views\Plugin\views\display\DisplayPluginBase;
use Drupal\views\ManyToOneHelper;
@ -30,23 +31,23 @@ class StringArgument extends ArgumentPluginBase {
// Ensure defaults for these, during summaries and stuff:
$this->operator = 'or';
$this->value = array();
$this->value = [];
}
}
protected function defineOptions() {
$options = parent::defineOptions();
$options['glossary'] = array('default' => FALSE);
$options['limit'] = array('default' => 0);
$options['case'] = array('default' => 'none');
$options['path_case'] = array('default' => 'none');
$options['transform_dash'] = array('default' => FALSE);
$options['break_phrase'] = array('default' => FALSE);
$options['glossary'] = ['default' => FALSE];
$options['limit'] = ['default' => 0];
$options['case'] = ['default' => 'none'];
$options['path_case'] = ['default' => 'none'];
$options['transform_dash'] = ['default' => FALSE];
$options['break_phrase'] = ['default' => FALSE];
if (!empty($this->definition['many to one'])) {
$options['add_table'] = array('default' => FALSE);
$options['require_value'] = array('default' => FALSE);
$options['add_table'] = ['default' => FALSE];
$options['require_value'] = ['default' => FALSE];
}
return $options;
@ -55,89 +56,89 @@ class StringArgument extends ArgumentPluginBase {
public function buildOptionsForm(&$form, FormStateInterface $form_state) {
parent::buildOptionsForm($form, $form_state);
$form['glossary'] = array(
$form['glossary'] = [
'#type' => 'checkbox',
'#title' => $this->t('Glossary mode'),
'#description' => $this->t('Glossary mode applies a limit to the number of characters used in the filter value, which allows the summary view to act as a glossary.'),
'#default_value' => $this->options['glossary'],
'#group' => 'options][more',
);
];
$form['limit'] = array(
$form['limit'] = [
'#type' => 'textfield',
'#title' => $this->t('Character limit'),
'#description' => $this->t('How many characters of the filter value to filter against. If set to 1, all fields starting with the first letter in the filter value would be matched.'),
'#default_value' => $this->options['limit'],
'#states' => array(
'visible' => array(
':input[name="options[glossary]"]' => array('checked' => TRUE),
),
),
'#states' => [
'visible' => [
':input[name="options[glossary]"]' => ['checked' => TRUE],
],
],
'#group' => 'options][more',
);
];
$form['case'] = array(
$form['case'] = [
'#type' => 'select',
'#title' => $this->t('Case'),
'#description' => $this->t('When printing the title and summary, how to transform the case of the filter value.'),
'#options' => array(
'#options' => [
'none' => $this->t('No transform'),
'upper' => $this->t('Upper case'),
'lower' => $this->t('Lower case'),
'ucfirst' => $this->t('Capitalize first letter'),
'ucwords' => $this->t('Capitalize each word'),
),
],
'#default_value' => $this->options['case'],
'#group' => 'options][more',
);
];
$form['path_case'] = array(
$form['path_case'] = [
'#type' => 'select',
'#title' => $this->t('Case in path'),
'#description' => $this->t('When printing URL paths, how to transform the case of the filter value. Do not use this unless with Postgres as it uses case sensitive comparisons.'),
'#options' => array(
'#options' => [
'none' => $this->t('No transform'),
'upper' => $this->t('Upper case'),
'lower' => $this->t('Lower case'),
'ucfirst' => $this->t('Capitalize first letter'),
'ucwords' => $this->t('Capitalize each word'),
),
],
'#default_value' => $this->options['path_case'],
'#group' => 'options][more',
);
];
$form['transform_dash'] = array(
$form['transform_dash'] = [
'#type' => 'checkbox',
'#title' => $this->t('Transform spaces to dashes in URL'),
'#default_value' => $this->options['transform_dash'],
'#group' => 'options][more',
);
];
if (!empty($this->definition['many to one'])) {
$form['add_table'] = array(
$form['add_table'] = [
'#type' => 'checkbox',
'#title' => $this->t('Allow multiple filter values to work together'),
'#description' => $this->t('If selected, multiple instances of this filter can work together, as though multiple values were supplied to the same filter. This setting is not compatible with the "Reduce duplicates" setting.'),
'#default_value' => !empty($this->options['add_table']),
'#group' => 'options][more',
);
];
$form['require_value'] = array(
$form['require_value'] = [
'#type' => 'checkbox',
'#title' => $this->t('Do not display items with no value in summary'),
'#default_value' => !empty($this->options['require_value']),
'#group' => 'options][more',
);
];
}
// allow + for or, , for and
$form['break_phrase'] = array(
$form['break_phrase'] = [
'#type' => 'checkbox',
'#title' => $this->t('Allow multiple values'),
'#description' => $this->t('If selected, users can enter multiple values in the form of 1+2+3 (for OR) or 1,2,3 (for AND).'),
'#default_value' => !empty($this->options['break_phrase']),
'#group' => 'options][more',
);
];
}
/**
@ -205,7 +206,7 @@ class StringArgument extends ArgumentPluginBase {
$this->unpackArgumentValue();
}
else {
$this->value = array($argument);
$this->value = [$argument];
$this->operator = 'or';
}
@ -252,9 +253,9 @@ class StringArgument extends ArgumentPluginBase {
else {
$field .= ' = ' . $placeholder;
}
$placeholders = array(
$placeholders = [
$placeholder => $argument,
);
];
$this->query->addWhereExpression(0, $field, $placeholders);
}
else {
@ -274,10 +275,10 @@ class StringArgument extends ArgumentPluginBase {
* {@inheritdoc}
*/
public function getSortName() {
return $this->t('Alphabetical', array(), array('context' => 'Sort order'));
return $this->t('Alphabetical', [], ['context' => 'Sort order']);
}
function title() {
public function title() {
// Support case-insensitive title comparisons for PostgreSQL by converting
// the title to lowercase.
if ($this->options['case'] != 'none' && Database::getConnection()->databaseType() == 'pgsql') {
@ -293,7 +294,7 @@ class StringArgument extends ArgumentPluginBase {
$this->unpackArgumentValue();
}
else {
$this->value = array($this->argument);
$this->value = [$this->argument];
$this->operator = 'or';
}
@ -301,7 +302,7 @@ class StringArgument extends ArgumentPluginBase {
return !empty($this->definition['empty field name']) ? $this->definition['empty field name'] : $this->t('Uncategorized');
}
if ($this->value === array(-1)) {
if ($this->value === [-1]) {
return !empty($this->definition['invalid input']) ? $this->definition['invalid input'] : $this->t('Invalid input');
}
@ -319,4 +320,17 @@ class StringArgument extends ArgumentPluginBase {
return $this->caseTransform(parent::summaryName($data), $this->options['case']);
}
/**
* {@inheritdoc}
*/
public function getContextDefinition() {
if ($context_definition = parent::getContextDefinition()) {
return $context_definition;
}
// If the parent does not provide a context definition through the
// validation plugin, fall back to the string type.
return new ContextDefinition('string', $this->adminLabel(), FALSE);
}
}

View file

@ -19,7 +19,7 @@ class WeekDate extends Date {
*/
public function summaryName($data) {
$created = $data->{$this->name_alias};
return $this->t('Week @week', array('@week' => $created));
return $this->t('Week @week', ['@week' => $created]);
}
}

View file

@ -30,7 +30,7 @@ class YearMonthDate extends Date {
/**
* Provide a link to the next level of the view
*/
function title() {
public function title() {
return format_date(strtotime($this->argument . "15" . " 00:00:00 UTC"), 'custom', $this->format, 'UTC');
}

View file

@ -58,7 +58,7 @@ abstract class ArgumentDefaultPluginBase extends PluginBase {
* Retrieve the options when this is a new access
* control plugin
*/
protected function defineOptions() { return array(); }
protected function defineOptions() { return []; }
/**
* Provide the default form for setting options.
@ -73,7 +73,7 @@ abstract class ArgumentDefaultPluginBase extends PluginBase {
/**
* Provide the default form form for submitting options
*/
public function submitOptionsForm(&$form, FormStateInterface $form_state, &$options = array()) { }
public function submitOptionsForm(&$form, FormStateInterface $form_state, &$options = []) { }
/**
* Determine if the administrator has the privileges to use this

View file

@ -23,7 +23,7 @@ class Fixed extends ArgumentDefaultPluginBase implements CacheableDependencyInte
*/
protected function defineOptions() {
$options = parent::defineOptions();
$options['argument'] = array('default' => '');
$options['argument'] = ['default' => ''];
return $options;
}
@ -33,11 +33,11 @@ class Fixed extends ArgumentDefaultPluginBase implements CacheableDependencyInte
*/
public function buildOptionsForm(&$form, FormStateInterface $form_state) {
parent::buildOptionsForm($form, $form_state);
$form['argument'] = array(
$form['argument'] = [
'#type' => 'textfield',
'#title' => $this->t('Fixed value'),
'#default_value' => $this->options['argument'],
);
];
}
/**

View file

@ -23,9 +23,9 @@ class QueryParameter extends ArgumentDefaultPluginBase implements CacheableDepen
*/
protected function defineOptions() {
$options = parent::defineOptions();
$options['query_param'] = array('default' => '');
$options['fallback'] = array('default' => '');
$options['multiple'] = array('default' => 'and');
$options['query_param'] = ['default' => ''];
$options['fallback'] = ['default' => ''];
$options['multiple'] = ['default' => 'and'];
return $options;
}
@ -35,28 +35,28 @@ class QueryParameter extends ArgumentDefaultPluginBase implements CacheableDepen
*/
public function buildOptionsForm(&$form, FormStateInterface $form_state) {
parent::buildOptionsForm($form, $form_state);
$form['query_param'] = array(
$form['query_param'] = [
'#type' => 'textfield',
'#title' => $this->t('Query parameter'),
'#description' => $this->t('The query parameter to use.'),
'#default_value' => $this->options['query_param'],
);
$form['fallback'] = array(
];
$form['fallback'] = [
'#type' => 'textfield',
'#title' => $this->t('Fallback value'),
'#description' => $this->t('The fallback value to use when the above query parameter is not present.'),
'#default_value' => $this->options['fallback'],
);
$form['multiple'] = array(
];
$form['multiple'] = [
'#type' => 'radios',
'#title' => $this->t('Multiple values'),
'#description' => $this->t('Conjunction to use when handling multiple values. E.g. "?value[0]=a&value[1]=b".'),
'#default_value' => $this->options['multiple'],
'#options' => array(
'#options' => [
'and' => $this->t('AND'),
'or' => $this->t('OR'),
),
);
],
];
}
/**

View file

@ -74,8 +74,8 @@ class Raw extends ArgumentDefaultPluginBase implements CacheableDependencyInterf
*/
protected function defineOptions() {
$options = parent::defineOptions();
$options['index'] = array('default' => '');
$options['use_alias'] = array('default' => FALSE);
$options['index'] = ['default' => ''];
$options['use_alias'] = ['default' => FALSE];
return $options;
}
@ -85,7 +85,7 @@ class Raw extends ArgumentDefaultPluginBase implements CacheableDependencyInterf
*/
public function buildOptionsForm(&$form, FormStateInterface $form_state) {
parent::buildOptionsForm($form, $form_state);
$form['index'] = array(
$form['index'] = [
'#type' => 'select',
'#title' => $this->t('Path component'),
'#default_value' => $this->options['index'],
@ -94,13 +94,13 @@ class Raw extends ArgumentDefaultPluginBase implements CacheableDependencyInterf
// - values that count from 1 for display to humans.
'#options' => range(1, 10),
'#description' => $this->t('The numbering starts from 1, e.g. on the page admin/structure/types, the 3rd path component is "types".'),
);
$form['use_alias'] = array(
];
$form['use_alias'] = [
'#type' => 'checkbox',
'#title' => $this->t('Use path alias'),
'#default_value' => $this->options['use_alias'],
'#description' => $this->t('Use path alias instead of internal path.'),
);
];
}
/**

View file

@ -53,7 +53,7 @@ abstract class ArgumentValidatorPluginBase extends PluginBase {
/**
* Retrieves the options when this is a new access control plugin.
*/
protected function defineOptions() { return array(); }
protected function defineOptions() { return []; }
/**
* Provides the default form for setting options.
@ -68,7 +68,7 @@ abstract class ArgumentValidatorPluginBase extends PluginBase {
/**
* Provides the default form for submitting options.
*/
public function submitOptionsForm(&$form, FormStateInterface $form_state, &$options = array()) { }
public function submitOptionsForm(&$form, FormStateInterface $form_state, &$options = []) { }
/**
* Determines if the administrator has the privileges to use this plugin.
@ -104,6 +104,15 @@ abstract class ArgumentValidatorPluginBase extends PluginBase {
*/
public function processSummaryArguments(&$args) { }
/**
* Returns a context definition for this argument.
*
* @return \Drupal\Core\Plugin\Context\ContextDefinitionInterface|null
* A context definition that represents the argument or NULL if that is
* not possible.
*/
public function getContextDefinition() { }
}
/**

View file

@ -5,6 +5,7 @@ namespace Drupal\views\Plugin\views\argument_validator;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Entity\EntityManagerInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Plugin\Context\ContextDefinition;
use Drupal\views\Plugin\views\argument\ArgumentPluginBase;
use Symfony\Component\DependencyInjection\ContainerInterface;
@ -70,10 +71,10 @@ class Entity extends ArgumentValidatorPluginBase {
protected function defineOptions() {
$options = parent::defineOptions();
$options['bundles'] = array('default' => array());
$options['access'] = array('default' => FALSE);
$options['operation'] = array('default' => 'view');
$options['multiple'] = array('default' => FALSE);
$options['bundles'] = ['default' => []];
$options['access'] = ['default' => FALSE];
$options['operation'] = ['default' => 'view'];
$options['multiple'] = ['default' => FALSE];
return $options;
}
@ -92,60 +93,60 @@ class Entity extends ArgumentValidatorPluginBase {
// If the entity has bundles, allow option to restrict to bundle(s).
if ($entity_type->hasKey('bundle')) {
$bundle_options = array();
$bundle_options = [];
foreach ($this->entityManager->getBundleInfo($entity_type_id) as $bundle_id => $bundle_info) {
$bundle_options[$bundle_id] = $bundle_info['label'];
}
$form['bundles'] = array(
$form['bundles'] = [
'#title' => $entity_type->getBundleLabel() ?: $this->t('Bundles'),
'#default_value' => $this->options['bundles'],
'#type' => 'checkboxes',
'#options' => $bundle_options,
'#description' => $this->t('If none are selected, all are allowed.'),
);
];
}
// Offer the option to filter by access to the entity in the argument.
$form['access'] = array(
$form['access'] = [
'#type' => 'checkbox',
'#title' => $this->t('Validate user has access to the %name', array('%name' => $entity_type->getLabel())),
'#title' => $this->t('Validate user has access to the %name', ['%name' => $entity_type->getLabel()]),
'#default_value' => $this->options['access'],
);
$form['operation'] = array(
];
$form['operation'] = [
'#type' => 'radios',
'#title' => $this->t('Access operation to check'),
'#options' => array(
'#options' => [
'view' => $this->t('View'),
'update' => $this->t('Edit'),
'delete' => $this->t('Delete'),
),
],
'#default_value' => $this->options['operation'],
'#states' => array(
'visible' => array(
':input[name="options[validate][options][' . $sanitized_id . '][access]"]' => array('checked' => TRUE),
),
),
);
'#states' => [
'visible' => [
':input[name="options[validate][options][' . $sanitized_id . '][access]"]' => ['checked' => TRUE],
],
],
];
// If class is multiple capable give the option to validate single/multiple.
if ($this->multipleCapable) {
$form['multiple'] = array(
$form['multiple'] = [
'#type' => 'radios',
'#title' => $this->t('Multiple arguments'),
'#options' => array(
0 => $this->t('Single ID', array('%type' => $entity_type->getLabel())),
1 => $this->t('One or more IDs separated by , or +', array('%type' => $entity_type->getLabel())),
),
'#options' => [
0 => $this->t('Single ID', ['%type' => $entity_type->getLabel()]),
1 => $this->t('One or more IDs separated by , or +', ['%type' => $entity_type->getLabel()]),
],
'#default_value' => (string) $this->options['multiple'],
);
];
}
}
/**
* {@inheritdoc}
*/
public function submitOptionsForm(&$form, FormStateInterface $form_state, &$options = array()) {
public function submitOptionsForm(&$form, FormStateInterface $form_state, &$options = []) {
// Filter out unused options so we don't store giant unnecessary arrays.
$options['bundles'] = array_filter($options['bundles']);
}
@ -162,7 +163,7 @@ class Entity extends ArgumentValidatorPluginBase {
$ids = array_filter(preg_split('/[,+ ]/', $argument));
}
elseif ($argument) {
$ids = array($argument);
$ids = [$argument];
}
// No specified argument should be invalid.
else {
@ -228,4 +229,11 @@ class Entity extends ArgumentValidatorPluginBase {
return $dependencies;
}
/**
* {@inheritdoc}
*/
public function getContextDefinition() {
return new ContextDefinition('entity:' . $this->definition['entity_type'], $this->argument->adminLabel(), FALSE);
}
}

View file

@ -2,6 +2,8 @@
namespace Drupal\views\Plugin\views\argument_validator;
use Drupal\Core\Plugin\Context\ContextDefinition;
/**
* Validate whether an argument is numeric or not.
*
@ -18,4 +20,11 @@ class NumericArgumentValidator extends ArgumentValidatorPluginBase {
return is_numeric($argument);
}
/**
* {@inheritdoc}
*/
public function getContextDefinition() {
return new ContextDefinition('integer', $this->argument->adminLabel(), FALSE);
}
}

View file

@ -31,7 +31,7 @@ abstract class CachePluginBase extends PluginBase {
/**
* Contains all data that should be written/read from cache.
*/
public $storage = array();
public $storage = [];
/**
* Which cache bin to store query results in.
@ -104,11 +104,11 @@ abstract class CachePluginBase extends PluginBase {
// Not supported currently, but this is certainly where we'd put it.
break;
case 'results':
$data = array(
$data = [
'result' => $this->prepareViewResult($this->view->result),
'total_rows' => isset($this->view->total_rows) ? $this->view->total_rows : 0,
'current_page' => $this->view->getCurrentPage(),
);
];
$expire = ($this->cacheSetMaxAge($type) === Cache::PERMANENT) ? Cache::PERMANENT : (int) $this->view->getRequest()->server->get('REQUEST_TIME') + $this->cacheSetMaxAge($type);
\Drupal::cache($this->resultsBin)->set($this->generateResultsKey(), $data, $expire, $this->getCacheTags());
break;
@ -183,16 +183,16 @@ abstract class CachePluginBase extends PluginBase {
if (!isset($this->resultsKey)) {
$build_info = $this->view->build_info;
foreach (array('query', 'count_query') as $index) {
foreach (['query', 'count_query'] as $index) {
// If the default query back-end is used generate SQL query strings from
// the query objects.
if ($build_info[$index] instanceof Select) {
$query = clone $build_info[$index];
$query->preExecute();
$build_info[$index] = array(
$build_info[$index] = [
'query' => (string)$query,
'arguments' => $query->getArguments(),
);
];
}
}
@ -263,7 +263,7 @@ abstract class CachePluginBase extends PluginBase {
* @param \Drupal\views\ResultRow[] $result
* The result containing loaded entities.
*
* @return \Drupal\views\ResultRow[] $result
* @return \Drupal\views\ResultRow[]
* The result without loaded entities.
*/
protected function prepareViewResult(array $result) {

View file

@ -76,64 +76,64 @@ class Time extends CachePluginBase {
protected function defineOptions() {
$options = parent::defineOptions();
$options['results_lifespan'] = array('default' => 3600);
$options['results_lifespan_custom'] = array('default' => 0);
$options['output_lifespan'] = array('default' => 3600);
$options['output_lifespan_custom'] = array('default' => 0);
$options['results_lifespan'] = ['default' => 3600];
$options['results_lifespan_custom'] = ['default' => 0];
$options['output_lifespan'] = ['default' => 3600];
$options['output_lifespan_custom'] = ['default' => 0];
return $options;
}
public function buildOptionsForm(&$form, FormStateInterface $form_state) {
parent::buildOptionsForm($form, $form_state);
$options = array(60, 300, 1800, 3600, 21600, 518400);
$options = array_map(array($this->dateFormatter, 'formatInterval'), array_combine($options, $options));
$options = array(0 => $this->t('Never cache')) + $options + array('custom' => $this->t('Custom'));
$options = [60, 300, 1800, 3600, 21600, 518400];
$options = array_map([$this->dateFormatter, 'formatInterval'], array_combine($options, $options));
$options = [0 => $this->t('Never cache')] + $options + ['custom' => $this->t('Custom')];
$form['results_lifespan'] = array(
$form['results_lifespan'] = [
'#type' => 'select',
'#title' => $this->t('Query results'),
'#description' => $this->t('The length of time raw query results should be cached.'),
'#options' => $options,
'#default_value' => $this->options['results_lifespan'],
);
$form['results_lifespan_custom'] = array(
];
$form['results_lifespan_custom'] = [
'#type' => 'textfield',
'#title' => $this->t('Seconds'),
'#size' => '25',
'#maxlength' => '30',
'#description' => $this->t('Length of time in seconds raw query results should be cached.'),
'#default_value' => $this->options['results_lifespan_custom'],
'#states' => array(
'visible' => array(
':input[name="cache_options[results_lifespan]"]' => array('value' => 'custom'),
),
),
);
$form['output_lifespan'] = array(
'#states' => [
'visible' => [
':input[name="cache_options[results_lifespan]"]' => ['value' => 'custom'],
],
],
];
$form['output_lifespan'] = [
'#type' => 'select',
'#title' => $this->t('Rendered output'),
'#description' => $this->t('The length of time rendered HTML output should be cached.'),
'#options' => $options,
'#default_value' => $this->options['output_lifespan'],
);
$form['output_lifespan_custom'] = array(
];
$form['output_lifespan_custom'] = [
'#type' => 'textfield',
'#title' => $this->t('Seconds'),
'#size' => '25',
'#maxlength' => '30',
'#description' => $this->t('Length of time in seconds rendered HTML output should be cached.'),
'#default_value' => $this->options['output_lifespan_custom'],
'#states' => array(
'visible' => array(
':input[name="cache_options[output_lifespan]"]' => array('value' => 'custom'),
),
),
);
'#states' => [
'visible' => [
':input[name="cache_options[output_lifespan]"]' => ['value' => 'custom'],
],
],
];
}
public function validateOptionsForm(&$form, FormStateInterface $form_state) {
$custom_fields = array('output_lifespan', 'results_lifespan');
$custom_fields = ['output_lifespan', 'results_lifespan'];
foreach ($custom_fields as $field) {
$cache_options = $form_state->getValue('cache_options');
if ($cache_options[$field] == 'custom' && !is_numeric($cache_options[$field . '_custom'])) {

View file

@ -34,12 +34,12 @@ class Attachment extends DisplayPluginBase {
protected function defineOptions() {
$options = parent::defineOptions();
$options['displays'] = array('default' => array());
$options['attachment_position'] = array('default' => 'before');
$options['inherit_arguments'] = array('default' => TRUE);
$options['inherit_exposed_filters'] = array('default' => FALSE);
$options['inherit_pager'] = array('default' => FALSE);
$options['render_pager'] = array('default' => FALSE);
$options['displays'] = ['default' => []];
$options['attachment_position'] = ['default' => 'before'];
$options['inherit_arguments'] = ['default' => TRUE];
$options['inherit_exposed_filters'] = ['default' => FALSE];
$options['inherit_pager'] = ['default' => FALSE];
$options['render_pager'] = ['default' => FALSE];
return $options;
}
@ -49,11 +49,11 @@ class Attachment extends DisplayPluginBase {
}
public function attachmentPositions($position = NULL) {
$positions = array(
$positions = [
'before' => $this->t('Before'),
'after' => $this->t('After'),
'both' => $this->t('Both'),
);
];
if ($position) {
return $positions[$position];
@ -71,13 +71,13 @@ class Attachment extends DisplayPluginBase {
// It is very important to call the parent function here:
parent::optionsSummary($categories, $options);
$categories['attachment'] = array(
$categories['attachment'] = [
'title' => $this->t('Attachment settings'),
'column' => 'second',
'build' => array(
'build' => [
'#weight' => -10,
),
);
],
];
$displays = array_filter($this->getOption('displays'));
if (count($displays) > 1) {
@ -94,41 +94,41 @@ class Attachment extends DisplayPluginBase {
$attach_to = $this->t('Not defined');
}
$options['displays'] = array(
$options['displays'] = [
'category' => 'attachment',
'title' => $this->t('Attach to'),
'value' => $attach_to,
);
];
$options['attachment_position'] = array(
$options['attachment_position'] = [
'category' => 'attachment',
'title' => $this->t('Attachment position'),
'value' => $this->attachmentPositions($this->getOption('attachment_position')),
);
];
$options['inherit_arguments'] = array(
$options['inherit_arguments'] = [
'category' => 'attachment',
'title' => $this->t('Inherit contextual filters'),
'value' => $this->getOption('inherit_arguments') ? $this->t('Yes') : $this->t('No'),
);
];
$options['inherit_exposed_filters'] = array(
$options['inherit_exposed_filters'] = [
'category' => 'attachment',
'title' => $this->t('Inherit exposed filters'),
'value' => $this->getOption('inherit_exposed_filters') ? $this->t('Yes') : $this->t('No'),
);
];
$options['inherit_pager'] = array(
$options['inherit_pager'] = [
'category' => 'pager',
'title' => $this->t('Inherit pager'),
'value' => $this->getOption('inherit_pager') ? $this->t('Yes') : $this->t('No'),
);
];
$options['render_pager'] = array(
$options['render_pager'] = [
'category' => 'pager',
'title' => $this->t('Render pager'),
'value' => $this->getOption('render_pager') ? $this->t('Yes') : $this->t('No'),
);
];
}
@ -142,65 +142,65 @@ class Attachment extends DisplayPluginBase {
switch ($form_state->get('section')) {
case 'inherit_arguments':
$form['#title'] .= $this->t('Inherit contextual filters');
$form['inherit_arguments'] = array(
$form['inherit_arguments'] = [
'#type' => 'checkbox',
'#title' => $this->t('Inherit'),
'#description' => $this->t('Should this display inherit its contextual filter values from the parent display to which it is attached?'),
'#default_value' => $this->getOption('inherit_arguments'),
);
];
break;
case 'inherit_exposed_filters':
$form['#title'] .= $this->t('Inherit exposed filters');
$form['inherit_exposed_filters'] = array(
$form['inherit_exposed_filters'] = [
'#type' => 'checkbox',
'#title' => $this->t('Inherit'),
'#description' => $this->t('Should this display inherit its exposed filter values from the parent display to which it is attached?'),
'#default_value' => $this->getOption('inherit_exposed_filters'),
);
];
break;
case 'inherit_pager':
$form['#title'] .= $this->t('Inherit pager');
$form['inherit_pager'] = array(
$form['inherit_pager'] = [
'#type' => 'checkbox',
'#title' => $this->t('Inherit'),
'#description' => $this->t('Should this display inherit its paging values from the parent display to which it is attached?'),
'#default_value' => $this->getOption('inherit_pager'),
);
];
break;
case 'render_pager':
$form['#title'] .= $this->t('Render pager');
$form['render_pager'] = array(
$form['render_pager'] = [
'#type' => 'checkbox',
'#title' => $this->t('Render'),
'#description' => $this->t('Should this display render the pager values? This is only meaningful if inheriting a pager.'),
'#default_value' => $this->getOption('render_pager'),
);
];
break;
case 'attachment_position':
$form['#title'] .= $this->t('Position');
$form['attachment_position'] = array(
$form['attachment_position'] = [
'#title' => $this->t('Position'),
'#type' => 'radios',
'#description' => $this->t('Attach before or after the parent display?'),
'#options' => $this->attachmentPositions(),
'#default_value' => $this->getOption('attachment_position'),
);
];
break;
case 'displays':
$form['#title'] .= $this->t('Attach to');
$displays = array();
$displays = [];
foreach ($this->view->storage->get('display') as $display_id => $display) {
if ($this->view->displayHandlers->has($display_id) && $this->view->displayHandlers->get($display_id)->acceptAttachments()) {
$displays[$display_id] = $display['display_title'];
}
}
$form['displays'] = array(
$form['displays'] = [
'#title' => $this->t('Displays'),
'#type' => 'checkboxes',
'#description' => $this->t('Select which display or displays this should attach to.'),
'#options' => array_map('\Drupal\Component\Utility\Html::escape', $displays),
'#default_value' => $this->getOption('displays'),
);
];
break;
}
}
@ -240,7 +240,7 @@ class Attachment extends DisplayPluginBase {
return;
}
$args = $this->getOption('inherit_arguments') ? $this->view->args : array();
$args = $this->getOption('inherit_arguments') ? $this->view->args : [];
$view->setArguments($args);
$view->setDisplay($this->display['id']);
if ($this->getOption('inherit_pager')) {

View file

@ -78,15 +78,15 @@ class Block extends DisplayPluginBase {
protected function defineOptions() {
$options = parent::defineOptions();
$options['block_description'] = array('default' => '');
$options['block_category'] = array('default' => $this->t('Lists (Views)'));
$options['block_hide_empty'] = array('default' => FALSE);
$options['block_description'] = ['default' => ''];
$options['block_category'] = ['default' => $this->t('Lists (Views)')];
$options['block_hide_empty'] = ['default' => FALSE];
$options['allow'] = array(
'contains' => array(
'items_per_page' => array('default' => 'items_per_page'),
),
);
$options['allow'] = [
'contains' => [
'items_per_page' => ['default' => 'items_per_page'],
],
];
return $options;
}
@ -116,7 +116,7 @@ class Block extends DisplayPluginBase {
// display, and arguments should be set on the view.
$element = $this->view->render();
if ($this->outputIsEmpty() && $this->getOption('block_hide_empty') && empty($this->view->style_plugin->definition['even empty'])) {
return array();
return [];
}
else {
return $element;
@ -131,13 +131,13 @@ class Block extends DisplayPluginBase {
public function optionsSummary(&$categories, &$options) {
parent::optionsSummary($categories, $options);
$categories['block'] = array(
$categories['block'] = [
'title' => $this->t('Block settings'),
'column' => 'second',
'build' => array(
'build' => [
'#weight' => -10,
),
);
],
];
$block_description = strip_tags($this->getOption('block_description'));
if (empty($block_description)) {
@ -145,30 +145,30 @@ class Block extends DisplayPluginBase {
}
$block_category = $this->getOption('block_category');
$options['block_description'] = array(
$options['block_description'] = [
'category' => 'block',
'title' => $this->t('Block name'),
'value' => views_ui_truncate($block_description, 24),
);
$options['block_category'] = array(
];
$options['block_category'] = [
'category' => 'block',
'title' => $this->t('Block category'),
'value' => views_ui_truncate($block_category, 24),
);
];
$filtered_allow = array_filter($this->getOption('allow'));
$options['allow'] = array(
$options['allow'] = [
'category' => 'block',
'title' => $this->t('Allow settings'),
'value' => empty($filtered_allow) ? $this->t('None') : $this->t('Items per page'),
);
];
$options['block_hide_empty'] = array(
$options['block_hide_empty'] = [
'category' => 'other',
'title' => $this->t('Hide block if the view output is empty'),
'value' => $this->getOption('block_hide_empty') ? $this->t('Yes') : $this->t('No'),
);
];
}
/**
@ -180,53 +180,53 @@ class Block extends DisplayPluginBase {
switch ($form_state->get('section')) {
case 'block_description':
$form['#title'] .= $this->t('Block admin description');
$form['block_description'] = array(
$form['block_description'] = [
'#type' => 'textfield',
'#description' => $this->t('This will appear as the name of this block in administer >> structure >> blocks.'),
'#default_value' => $this->getOption('block_description'),
);
];
break;
case 'block_category':
$form['#title'] .= $this->t('Block category');
$form['block_category'] = array(
$form['block_category'] = [
'#type' => 'textfield',
'#autocomplete_route_name' => 'block.category_autocomplete',
'#description' => $this->t('The category this block will appear under on the <a href=":href">blocks placement page</a>.', array(':href' => \Drupal::url('block.admin_display'))),
'#description' => $this->t('The category this block will appear under on the <a href=":href">blocks placement page</a>.', [':href' => \Drupal::url('block.admin_display')]),
'#default_value' => $this->getOption('block_category'),
);
];
break;
case 'block_hide_empty':
$form['#title'] .= $this->t('Block empty settings');
$form['block_hide_empty'] = array(
$form['block_hide_empty'] = [
'#title' => $this->t('Hide block if no result/empty text'),
'#type' => 'checkbox',
'#description' => $this->t('Hide the block if there is no result and no empty text and no header/footer which is shown on empty result'),
'#default_value' => $this->getOption('block_hide_empty'),
);
];
break;
case 'exposed_form_options':
$this->view->initHandlers();
if (!$this->usesExposed() && parent::usesExposed()) {
$form['exposed_form_options']['warning'] = array(
$form['exposed_form_options']['warning'] = [
'#weight' => -10,
'#markup' => '<div class="messages messages--warning">' . $this->t('Exposed filters in block displays require "Use AJAX" to be set to work correctly.') . '</div>',
);
];
}
break;
case 'allow':
$form['#title'] .= $this->t('Allow settings in the block configuration');
$options = array(
$options = [
'items_per_page' => $this->t('Items per page'),
);
];
$allow = array_filter($this->getOption('allow'));
$form['allow'] = array(
$form['allow'] = [
'#type' => 'checkboxes',
'#default_value' => $allow,
'#options' => $options,
);
];
break;
}
}
@ -260,7 +260,7 @@ class Block extends DisplayPluginBase {
* @param \Drupal\Core\Form\FormStateInterface $form_state
* The current state of the form.
*
* @return array $form
* @return array
* The renderable form array representing the entire configuration form.
*
* @see \Drupal\views\Plugin\Block\ViewsBlock::blockForm()
@ -276,18 +276,18 @@ class Block extends DisplayPluginBase {
}
switch ($type) {
case 'items_per_page':
$form['override']['items_per_page'] = array(
$form['override']['items_per_page'] = [
'#type' => 'select',
'#title' => $this->t('Items per block'),
'#options' => array(
'none' => $this->t('@count (default setting)', array('@count' => $this->getPlugin('pager')->getItemsPerPage())),
'#options' => [
'none' => $this->t('@count (default setting)', ['@count' => $this->getPlugin('pager')->getItemsPerPage()]),
5 => 5,
10 => 10,
20 => 20,
40 => 40,
),
],
'#default_value' => $block_configuration['items_per_page'],
);
];
break;
}
}
@ -323,10 +323,10 @@ class Block extends DisplayPluginBase {
* @see \Drupal\views\Plugin\Block\ViewsBlock::blockSubmit()
*/
public function blockSubmit(ViewsBlock $block, $form, FormStateInterface $form_state) {
if ($items_per_page = $form_state->getValue(array('override', 'items_per_page'))) {
if ($items_per_page = $form_state->getValue(['override', 'items_per_page'])) {
$block->setConfigurationValue('items_per_page', $items_per_page);
}
$form_state->unsetValue(array('override', 'items_per_page'));
$form_state->unsetValue(['override', 'items_per_page']);
}
/**

View file

@ -497,7 +497,7 @@ interface DisplayPluginInterface {
*
* Also might be used for some other AJAXy reason.
*/
function preview();
public function preview();
/**
* Returns the display type that this display requires.

View file

@ -47,9 +47,9 @@ class EntityReference extends DisplayPluginBase {
// Force the style plugin to 'entity_reference_style' and the row plugin to
// 'fields'.
$options['style']['contains']['type'] = array('default' => 'entity_reference');
$options['style']['contains']['type'] = ['default' => 'entity_reference'];
$options['defaults']['default']['style'] = FALSE;
$options['row']['contains']['type'] = array('default' => 'entity_reference');
$options['row']['contains']['type'] = ['default' => 'entity_reference'];
$options['defaults']['default']['row'] = FALSE;
// Make sure the query is not cached.
@ -165,14 +165,14 @@ class EntityReference extends DisplayPluginBase {
// Verify that search fields are set up.
$style = $this->getOption('style');
if (!isset($style['options']['search_fields'])) {
$errors[] = $this->t('Display "@display" needs a selected search fields to work properly. See the settings for the Entity Reference list format.', array('@display' => $this->display['display_title']));
$errors[] = $this->t('Display "@display" needs a selected search fields to work properly. See the settings for the Entity Reference list format.', ['@display' => $this->display['display_title']]);
}
else {
// Verify that the search fields used actually exist.
$fields = array_keys($this->handlers['field']);
foreach ($style['options']['search_fields'] as $field_alias => $enabled) {
if ($enabled && !in_array($field_alias, $fields)) {
$errors[] = $this->t('Display "@display" uses field %field as search field, but the field is no longer present. See the settings for the Entity Reference list format.', array('@display' => $this->display['display_title'], '%field' => $field_alias));
$errors[] = $this->t('Display "@display" uses field %field as search field, but the field is no longer present. See the settings for the Entity Reference list format.', ['@display' => $this->display['display_title'], '%field' => $field_alias]);
}
}
}

View file

@ -90,11 +90,11 @@ class Feed extends PathPluginBase implements ResponseDisplayPluginInterface {
$output = $this->view->render();
if (!empty($this->view->live_preview)) {
$output = array(
$output = [
'#prefix' => '<pre>',
'#plain_text' => drupal_render_root($output),
'#suffix' => '</pre>',
);
];
}
return $output;
@ -117,7 +117,7 @@ class Feed extends PathPluginBase implements ResponseDisplayPluginInterface {
public function defaultableSections($section = NULL) {
$sections = parent::defaultableSections($section);
if (in_array($section, array('style', 'row'))) {
if (in_array($section, ['style', 'row'])) {
return FALSE;
}
@ -137,11 +137,11 @@ class Feed extends PathPluginBase implements ResponseDisplayPluginInterface {
protected function defineOptions() {
$options = parent::defineOptions();
$options['displays'] = array('default' => array());
$options['displays'] = ['default' => []];
// Overrides for standard stuff.
$options['style']['contains']['type']['default'] = 'rss';
$options['style']['contains']['options']['default'] = array('description' => '');
$options['style']['contains']['options']['default'] = ['description' => ''];
$options['sitename_title']['default'] = FALSE;
$options['row']['contains']['type']['default'] = 'rss_fields';
$options['defaults']['default']['style'] = FALSE;
@ -160,7 +160,7 @@ class Feed extends PathPluginBase implements ResponseDisplayPluginInterface {
// definition, but in this case it's dependent on the view's base table,
// which we don't know until init().
if (empty($this->options['row']['type']) || $this->options['row']['type'] === 'rss_fields') {
$row_plugins = Views::fetchPluginNames('row', $this->getType(), array($this->view->storage->get('base_table')));
$row_plugins = Views::fetchPluginNames('row', $this->getType(), [$this->view->storage->get('base_table')]);
$default_row_plugin = key($row_plugins);
$options = $this->getOption('row');
@ -177,13 +177,13 @@ class Feed extends PathPluginBase implements ResponseDisplayPluginInterface {
// Since we're childing off the 'path' type, we'll still *call* our
// category 'page' but let's override it so it says feed settings.
$categories['page'] = array(
$categories['page'] = [
'title' => $this->t('Feed settings'),
'column' => 'second',
'build' => array(
'build' => [
'#weight' => -10,
),
);
],
];
if ($this->getOption('sitename_title')) {
$options['title']['value'] = $this->t('Using the site name');
@ -205,11 +205,11 @@ class Feed extends PathPluginBase implements ResponseDisplayPluginInterface {
$attach_to = $this->t('None');
}
$options['displays'] = array(
$options['displays'] = [
'category' => 'page',
'title' => $this->t('Attach to'),
'value' => $attach_to,
);
];
}
/**
@ -224,34 +224,34 @@ class Feed extends PathPluginBase implements ResponseDisplayPluginInterface {
$title = $form['title'];
// A little juggling to move the 'title' field beyond our checkbox.
unset($form['title']);
$form['sitename_title'] = array(
$form['sitename_title'] = [
'#type' => 'checkbox',
'#title' => $this->t('Use the site name for the title'),
'#default_value' => $this->getOption('sitename_title'),
);
];
$form['title'] = $title;
$form['title']['#states'] = array(
'visible' => array(
':input[name="sitename_title"]' => array('checked' => FALSE),
),
);
$form['title']['#states'] = [
'visible' => [
':input[name="sitename_title"]' => ['checked' => FALSE],
],
];
break;
case 'displays':
$form['#title'] .= $this->t('Attach to');
$displays = array();
$displays = [];
foreach ($this->view->storage->get('display') as $display_id => $display) {
// @todo The display plugin should have display_title and id as well.
if ($this->view->displayHandlers->has($display_id) && $this->view->displayHandlers->get($display_id)->acceptAttachments()) {
$displays[$display_id] = $display['display_title'];
}
}
$form['displays'] = array(
$form['displays'] = [
'#title' => $this->t('Displays'),
'#type' => 'checkboxes',
'#description' => $this->t('The feed icon will be available only to the selected displays.'),
'#options' => array_map('\Drupal\Component\Utility\Html::escape', $displays),
'#default_value' => $this->getOption('displays'),
);
];
break;
case 'path':
$form['path']['#description'] = $this->t('This view will be displayed by visiting this path on your site. It is recommended that the path be something like "path/%/%/feed" or "path/%/%/rss.xml", putting one % in the path for each contextual filter you have defined in the view.');

View file

@ -118,27 +118,27 @@ class Page extends PathPluginBase {
protected function defineOptions() {
$options = parent::defineOptions();
$options['menu'] = array(
'contains' => array(
'type' => array('default' => 'none'),
'title' => array('default' => ''),
'description' => array('default' => ''),
'weight' => array('default' => 0),
'enabled' => array('default' => TRUE),
'menu_name' => array('default' => 'main'),
'parent' => array('default' => ''),
'context' => array('default' => ''),
'expanded' => array('default' => FALSE),
),
);
$options['tab_options'] = array(
'contains' => array(
'type' => array('default' => 'none'),
'title' => array('default' => ''),
'description' => array('default' => ''),
'weight' => array('default' => 0),
),
);
$options['menu'] = [
'contains' => [
'type' => ['default' => 'none'],
'title' => ['default' => ''],
'description' => ['default' => ''],
'weight' => ['default' => 0],
'enabled' => ['default' => TRUE],
'menu_name' => ['default' => 'main'],
'parent' => ['default' => ''],
'context' => ['default' => ''],
'expanded' => ['default' => FALSE],
],
];
$options['tab_options'] = [
'contains' => [
'type' => ['default' => 'none'],
'title' => ['default' => ''],
'description' => ['default' => ''],
'weight' => ['default' => 0],
],
];
return $options;
}
@ -175,9 +175,9 @@ class Page extends PathPluginBase {
// @todo Figure out how to support custom response objects. Maybe for pages
// it should be dropped.
if (is_array($render)) {
$render += array(
$render += [
'#title' => ['#markup' => $this->view->getTitle(), '#allowed_tags' => Xss::getHtmlTagList()],
);
];
}
return $render;
}
@ -190,7 +190,7 @@ class Page extends PathPluginBase {
$menu = $this->getOption('menu');
if (!is_array($menu)) {
$menu = array('type' => 'none');
$menu = ['type' => 'none'];
}
switch ($menu['type']) {
case 'none':
@ -198,19 +198,19 @@ class Page extends PathPluginBase {
$menu_str = $this->t('No menu');
break;
case 'normal':
$menu_str = $this->t('Normal: @title', array('@title' => $menu['title']));
$menu_str = $this->t('Normal: @title', ['@title' => $menu['title']]);
break;
case 'tab':
case 'default tab':
$menu_str = $this->t('Tab: @title', array('@title' => $menu['title']));
$menu_str = $this->t('Tab: @title', ['@title' => $menu['title']]);
break;
}
$options['menu'] = array(
$options['menu'] = [
'category' => 'page',
'title' => $this->t('Menu'),
'value' => views_ui_truncate($menu_str, 24),
);
];
// This adds a 'Settings' link to the style_options setting if the style
// has options.
@ -229,67 +229,67 @@ class Page extends PathPluginBase {
switch ($form_state->get('section')) {
case 'menu':
$form['#title'] .= $this->t('Menu item entry');
$form['menu'] = array(
$form['menu'] = [
'#prefix' => '<div class="clearfix">',
'#suffix' => '</div>',
'#tree' => TRUE,
);
];
$menu = $this->getOption('menu');
if (empty($menu)) {
$menu = array('type' => 'none', 'title' => '', 'weight' => 0, 'expanded' => FALSE);
$menu = ['type' => 'none', 'title' => '', 'weight' => 0, 'expanded' => FALSE];
}
$form['menu']['type'] = array(
$form['menu']['type'] = [
'#prefix' => '<div class="views-left-30">',
'#suffix' => '</div>',
'#title' => $this->t('Type'),
'#type' => 'radios',
'#options' => array(
'#options' => [
'none' => $this->t('No menu entry'),
'normal' => $this->t('Normal menu entry'),
'tab' => $this->t('Menu tab'),
'default tab' => $this->t('Default menu tab')
),
],
'#default_value' => $menu['type'],
);
];
$form['menu']['title'] = array(
$form['menu']['title'] = [
'#prefix' => '<div class="views-left-50">',
'#title' => $this->t('Menu link title'),
'#type' => 'textfield',
'#default_value' => $menu['title'],
'#states' => array(
'visible' => array(
array(
':input[name="menu[type]"]' => array('value' => 'normal'),
),
array(
':input[name="menu[type]"]' => array('value' => 'tab'),
),
array(
':input[name="menu[type]"]' => array('value' => 'default tab'),
),
),
),
);
$form['menu']['description'] = array(
'#states' => [
'visible' => [
[
':input[name="menu[type]"]' => ['value' => 'normal'],
],
[
':input[name="menu[type]"]' => ['value' => 'tab'],
],
[
':input[name="menu[type]"]' => ['value' => 'default tab'],
],
],
],
];
$form['menu']['description'] = [
'#title' => $this->t('Description'),
'#type' => 'textfield',
'#default_value' => $menu['description'],
'#description' => $this->t("Shown when hovering over the menu link."),
'#states' => array(
'visible' => array(
array(
':input[name="menu[type]"]' => array('value' => 'normal'),
),
array(
':input[name="menu[type]"]' => array('value' => 'tab'),
),
array(
':input[name="menu[type]"]' => array('value' => 'default tab'),
),
),
),
);
'#states' => [
'visible' => [
[
':input[name="menu[type]"]' => ['value' => 'normal'],
],
[
':input[name="menu[type]"]' => ['value' => 'tab'],
],
[
':input[name="menu[type]"]' => ['value' => 'default tab'],
],
],
],
];
$form['menu']['expanded'] = [
'#title' => $this->t('Show as expanded'),
'#type' => 'checkbox',
@ -302,133 +302,133 @@ class Page extends PathPluginBase {
if (\Drupal::moduleHandler()->moduleExists('menu_ui')) {
$menu_link = 'views_view:views.' . $form_state->get('view')->id() . '.' . $form_state->get('display_id');
$form['menu']['parent'] = \Drupal::service('menu.parent_form_selector')->parentSelectElement($menu_parent, $menu_link);
$form['menu']['parent'] += array(
$form['menu']['parent'] += [
'#title' => $this->t('Parent'),
'#description' => $this->t('The maximum depth for a link and all its children is fixed. Some menu links may not be available as parents if selecting them would exceed this limit.'),
'#attributes' => array('class' => array('menu-title-select')),
'#states' => array(
'visible' => array(
array(
':input[name="menu[type]"]' => array('value' => 'normal'),
),
array(
':input[name="menu[type]"]' => array('value' => 'tab'),
),
),
),
);
'#attributes' => ['class' => ['menu-title-select']],
'#states' => [
'visible' => [
[
':input[name="menu[type]"]' => ['value' => 'normal'],
],
[
':input[name="menu[type]"]' => ['value' => 'tab'],
],
],
],
];
}
else {
$form['menu']['parent'] = array(
$form['menu']['parent'] = [
'#type' => 'value',
'#value' => $menu_parent,
);
$form['menu']['markup'] = array(
];
$form['menu']['markup'] = [
'#markup' => $this->t('Menu selection requires the activation of Menu UI module.'),
);
];
}
$form['menu']['weight'] = array(
$form['menu']['weight'] = [
'#title' => $this->t('Weight'),
'#type' => 'textfield',
'#default_value' => isset($menu['weight']) ? $menu['weight'] : 0,
'#description' => $this->t('In the menu, the heavier links will sink and the lighter links will be positioned nearer the top.'),
'#states' => array(
'visible' => array(
array(
':input[name="menu[type]"]' => array('value' => 'normal'),
),
array(
':input[name="menu[type]"]' => array('value' => 'tab'),
),
array(
':input[name="menu[type]"]' => array('value' => 'default tab'),
),
),
),
);
$form['menu']['context'] = array(
'#states' => [
'visible' => [
[
':input[name="menu[type]"]' => ['value' => 'normal'],
],
[
':input[name="menu[type]"]' => ['value' => 'tab'],
],
[
':input[name="menu[type]"]' => ['value' => 'default tab'],
],
],
],
];
$form['menu']['context'] = [
'#title' => $this->t('Context'),
'#suffix' => '</div>',
'#type' => 'checkbox',
'#default_value' => !empty($menu['context']),
'#description' => $this->t('Displays the link in contextual links'),
'#states' => array(
'visible' => array(
':input[name="menu[type]"]' => array('value' => 'tab'),
),
),
);
'#states' => [
'visible' => [
':input[name="menu[type]"]' => ['value' => 'tab'],
],
],
];
break;
case 'tab_options':
$form['#title'] .= $this->t('Default tab options');
$tab_options = $this->getOption('tab_options');
if (empty($tab_options)) {
$tab_options = array('type' => 'none', 'title' => '', 'weight' => 0);
$tab_options = ['type' => 'none', 'title' => '', 'weight' => 0];
}
$form['tab_markup'] = array(
$form['tab_markup'] = [
'#markup' => '<div class="js-form-item form-item description">' . $this->t('When providing a menu item as a tab, Drupal needs to know what the parent menu item of that tab will be. Sometimes the parent will already exist, but other times you will need to have one created. The path of a parent item will always be the same path with the last part left off. i.e, if the path to this view is <em>foo/bar/baz</em>, the parent path would be <em>foo/bar</em>.') . '</div>',
);
];
$form['tab_options'] = array(
$form['tab_options'] = [
'#prefix' => '<div class="clearfix">',
'#suffix' => '</div>',
'#tree' => TRUE,
);
$form['tab_options']['type'] = array(
];
$form['tab_options']['type'] = [
'#prefix' => '<div class="views-left-25">',
'#suffix' => '</div>',
'#title' => $this->t('Parent menu item'),
'#type' => 'radios',
'#options' => array('none' => $this->t('Already exists'), 'normal' => $this->t('Normal menu item'), 'tab' => $this->t('Menu tab')),
'#options' => ['none' => $this->t('Already exists'), 'normal' => $this->t('Normal menu item'), 'tab' => $this->t('Menu tab')],
'#default_value' => $tab_options['type'],
);
$form['tab_options']['title'] = array(
];
$form['tab_options']['title'] = [
'#prefix' => '<div class="views-left-75">',
'#title' => $this->t('Title'),
'#type' => 'textfield',
'#default_value' => $tab_options['title'],
'#description' => $this->t('If creating a parent menu item, enter the title of the item.'),
'#states' => array(
'visible' => array(
array(
':input[name="tab_options[type]"]' => array('value' => 'normal'),
),
array(
':input[name="tab_options[type]"]' => array('value' => 'tab'),
),
),
),
);
$form['tab_options']['description'] = array(
'#states' => [
'visible' => [
[
':input[name="tab_options[type]"]' => ['value' => 'normal'],
],
[
':input[name="tab_options[type]"]' => ['value' => 'tab'],
],
],
],
];
$form['tab_options']['description'] = [
'#title' => $this->t('Description'),
'#type' => 'textfield',
'#default_value' => $tab_options['description'],
'#description' => $this->t('If creating a parent menu item, enter the description of the item.'),
'#states' => array(
'visible' => array(
array(
':input[name="tab_options[type]"]' => array('value' => 'normal'),
),
array(
':input[name="tab_options[type]"]' => array('value' => 'tab'),
),
),
),
);
$form['tab_options']['weight'] = array(
'#states' => [
'visible' => [
[
':input[name="tab_options[type]"]' => ['value' => 'normal'],
],
[
':input[name="tab_options[type]"]' => ['value' => 'tab'],
],
],
],
];
$form['tab_options']['weight'] = [
'#suffix' => '</div>',
'#title' => $this->t('Tab weight'),
'#type' => 'textfield',
'#default_value' => $tab_options['weight'],
'#size' => 5,
'#description' => $this->t('If the parent menu item is a tab, enter the weight of the tab. Heavier tabs will sink and the lighter tabs will be positioned nearer to the first menu item.'),
'#states' => array(
'visible' => array(
':input[name="tab_options[type]"]' => array('value' => 'tab'),
),
),
);
'#states' => [
'visible' => [
':input[name="tab_options[type]"]' => ['value' => 'tab'],
],
],
];
break;
}
}
@ -441,7 +441,7 @@ class Page extends PathPluginBase {
if ($form_state->get('section') == 'menu') {
$path = $this->getOption('path');
$menu_type = $form_state->getValue(array('menu', 'type'));
$menu_type = $form_state->getValue(['menu', 'type']);
if ($menu_type == 'normal' && strpos($path, '%') !== FALSE) {
$form_state->setError($form['menu']['type'], $this->t('Views cannot create normal menu items for paths with a % in them.'));
}
@ -454,7 +454,7 @@ class Page extends PathPluginBase {
}
}
if ($menu_type != 'none' && $form_state->isValueEmpty(array('menu', 'title'))) {
if ($menu_type != 'none' && $form_state->isValueEmpty(['menu', 'title'])) {
$form_state->setError($form['menu']['title'], $this->t('Title is required for this menu type.'));
}
}
@ -472,7 +472,7 @@ class Page extends PathPluginBase {
list($menu['menu_name'], $menu['parent']) = explode(':', $menu['parent'], 2);
$this->setOption('menu', $menu);
// send ajax form to options page if we use it.
if ($form_state->getValue(array('menu', 'type')) == 'default tab') {
if ($form_state->getValue(['menu', 'type']) == 'default tab') {
$form_state->get('view')->addFormToStack('display', $this->display['id'], 'tab_options');
}
break;
@ -490,13 +490,13 @@ class Page extends PathPluginBase {
$menu = $this->getOption('menu');
if (!empty($menu['type']) && $menu['type'] != 'none' && empty($menu['title'])) {
$errors[] = $this->t('Display @display is set to use a menu but the menu link text is not set.', array('@display' => $this->display['display_title']));
$errors[] = $this->t('Display @display is set to use a menu but the menu link text is not set.', ['@display' => $this->display['display_title']]);
}
if ($menu['type'] == 'default tab') {
$tab_options = $this->getOption('tab_options');
if (!empty($tab_options['type']) && $tab_options['type'] != 'none' && empty($tab_options['title'])) {
$errors[] = $this->t('Display @display is set to use a parent menu but the parent menu link text is not set.', array('@display' => $this->display['display_title']));
$errors[] = $this->t('Display @display is set to use a parent menu but the parent menu link text is not set.', ['@display' => $this->display['display_title']]);
}
}
@ -507,21 +507,21 @@ class Page extends PathPluginBase {
* {@inheritdoc}
*/
public function getArgumentText() {
return array(
return [
'filter value not present' => $this->t('When the filter value is <em>NOT</em> in the URL'),
'filter value present' => $this->t('When the filter value <em>IS</em> in the URL or a default is provided'),
'description' => $this->t('The contextual filter values are provided by the URL.'),
);
];
}
/**
* {@inheritdoc}
*/
public function getPagerText() {
return array(
return [
'items per page title' => $this->t('Items per page'),
'items per page description' => $this->t('Enter 0 for no limit.')
);
];
}
/**

View file

@ -109,8 +109,8 @@ abstract class PathPluginBase extends DisplayPluginBase implements DisplayRouter
*/
protected function defineOptions() {
$options = parent::defineOptions();
$options['path'] = array('default' => '');
$options['route_name'] = array('default' => '');
$options['path'] = ['default' => ''];
$options['route_name'] = ['default' => ''];
return $options;
}
@ -127,13 +127,13 @@ abstract class PathPluginBase extends DisplayPluginBase implements DisplayRouter
* The route for the view.
*/
protected function getRoute($view_id, $display_id) {
$defaults = array(
$defaults = [
'_controller' => 'Drupal\views\Routing\ViewPageController::handle',
'_title' => $this->view->getTitle(),
'view_id' => $view_id,
'display_id' => $display_id,
'_view_display_show_admin_links' => $this->getOption('show_admin_links'),
);
];
// @todo How do we apply argument validation?
$bits = explode('/', $this->getOption('path'));
@ -145,7 +145,7 @@ abstract class PathPluginBase extends DisplayPluginBase implements DisplayRouter
$argument_ids = array_keys((array) $this->getOption('arguments'));
$total_arguments = count($argument_ids);
$argument_map = array();
$argument_map = [];
// Replace arguments in the views UI (defined via %) with parameters in
// routes (defined via {}). As a name for the parameter use arg_$key, so
@ -223,22 +223,65 @@ abstract class PathPluginBase extends DisplayPluginBase implements DisplayRouter
$route_name = "view.$view_id.$display_id";
}
$collection->add($route_name, $route);
return array("$view_id.$display_id" => $route_name);
return ["$view_id.$display_id" => $route_name];
}
/**
* Determines whether the view overrides the given route.
*
* @param string $view_path
* The path of the view.
* @param \Symfony\Component\Routing\Route $view_route
* The route of the view.
* @param \Symfony\Component\Routing\Route $route
* The route itself.
*
* @return bool
* TRUE, when the view should override the given route.
*/
protected function overrideApplies($view_path, Route $view_route, Route $route) {
return $this->overrideAppliesPathAndMethod($view_path, $view_route, $route)
&& (!$route->hasRequirement('_format') || $route->getRequirement('_format') === 'html');
}
/**
* Determines whether a override for the path and method should happen.
*
* @param string $view_path
* The path of the view.
* @param \Symfony\Component\Routing\Route $view_route
* The route of the view.
* @param \Symfony\Component\Routing\Route $route
* The route itself.
*
* @return bool
* TRUE, when the view should override the given route.
*/
protected function overrideAppliesPathAndMethod($view_path, Route $view_route, Route $route) {
// Find all paths which match the path of the current display..
$route_path = RouteCompiler::getPathWithoutDefaults($route);
$route_path = RouteCompiler::getPatternOutline($route_path);
// Ensure that we don't override a route which is already controlled by
// views.
return !$route->hasDefault('view_id')
&& ('/' . $view_path == $route_path)
// Also ensure that we don't override for example REST routes.
&& (!$route->getMethods() || in_array('GET', $route->getMethods()));
}
/**
* {@inheritdoc}
*/
public function alterRoutes(RouteCollection $collection) {
$view_route_names = array();
$view_route_names = [];
$view_path = $this->getPath();
$view_id = $this->view->storage->id();
$display_id = $this->display['id'];
$view_route = $this->getRoute($view_id, $display_id);
foreach ($collection->all() as $name => $route) {
// Find all paths which match the path of the current display..
$route_path = RouteCompiler::getPathWithoutDefaults($route);
$route_path = RouteCompiler::getPatternOutline($route_path);
// Ensure that we don't override a route which is already controlled by
// views. Also ensure that we don't override for example REST routes.
if (!$route->hasDefault('view_id') && ('/' . $view_path == $route_path) && (!$route->getMethods() || in_array('GET', $route->getMethods()))) {
if ($this->overrideApplies($view_path, $view_route, $route)) {
$parameters = $route->compile()->getPathVariables();
// @todo Figure out whether we need to merge some settings (like
@ -248,13 +291,9 @@ abstract class PathPluginBase extends DisplayPluginBase implements DisplayRouter
$original_route = $collection->get($name);
$collection->remove($name);
$view_id = $this->view->storage->id();
$display_id = $this->display['id'];
$route = $this->getRoute($view_id, $display_id);
$path = $route->getPath();
$path = $view_route->getPath();
// Replace the path with the original parameter names and add a mapping.
$argument_map = array();
$argument_map = [];
// We assume that the numeric ids of the parameters match the one from
// the view argument handlers.
foreach ($parameters as $position => $parameter_name) {
@ -263,17 +302,17 @@ abstract class PathPluginBase extends DisplayPluginBase implements DisplayRouter
}
// Copy the original options from the route, so for example we ensure
// that parameter conversion options is carried over.
$route->setOptions($route->getOptions() + $original_route->getOptions());
$view_route->setOptions($view_route->getOptions() + $original_route->getOptions());
if ($original_route->hasDefault('_title_callback')) {
$route->setDefault('_title_callback', $original_route->getDefault('_title_callback'));
$view_route->setDefault('_title_callback', $original_route->getDefault('_title_callback'));
}
// Set the corrected path and the mapping to the route object.
$route->setOption('_view_argument_map', $argument_map);
$route->setPath($path);
$view_route->setOption('_view_argument_map', $argument_map);
$view_route->setPath($path);
$collection->add($name, $route);
$collection->add($name, $view_route);
$view_route_names[$view_id . '.' . $display_id] = $name;
}
}
@ -285,7 +324,7 @@ abstract class PathPluginBase extends DisplayPluginBase implements DisplayRouter
* {@inheritdoc}
*/
public function getMenuLinks() {
$links = array();
$links = [];
// Replace % with the link to our standard views argument loader
// views_arg_load -- which lives in views.module.
@ -297,7 +336,7 @@ abstract class PathPluginBase extends DisplayPluginBase implements DisplayRouter
foreach ($bits as $pos => $bit) {
if ($bit == '%') {
// If a view requires any arguments we cannot create a static menu link.
return array();
return [];
}
}
@ -310,15 +349,15 @@ abstract class PathPluginBase extends DisplayPluginBase implements DisplayRouter
if ($path) {
$menu = $this->getOption('menu');
if (!empty($menu['type']) && $menu['type'] == 'normal') {
$links[$menu_link_id] = array();
$links[$menu_link_id] = [];
// Some views might override existing paths, so we have to set the route
// name based upon the altering.
$links[$menu_link_id] = array(
$links[$menu_link_id] = [
'route_name' => $this->getRouteName(),
// Identify URL embedded arguments and correlate them to a handler.
'load arguments' => array($this->view->storage->id(), $this->display['id'], '%index'),
'load arguments' => [$this->view->storage->id(), $this->display['id'], '%index'],
'id' => $menu_link_id,
);
];
$links[$menu_link_id]['title'] = $menu['title'];
$links[$menu_link_id]['description'] = $menu['description'];
$links[$menu_link_id]['parent'] = $menu['parent'];
@ -332,10 +371,10 @@ abstract class PathPluginBase extends DisplayPluginBase implements DisplayRouter
// Insert item into the proper menu.
$links[$menu_link_id]['menu_name'] = $menu['menu_name'];
// Keep track of where we came from.
$links[$menu_link_id]['metadata'] = array(
$links[$menu_link_id]['metadata'] = [
'view_id' => $view_id,
'display_id' => $display_id,
);
];
}
}
@ -365,13 +404,13 @@ abstract class PathPluginBase extends DisplayPluginBase implements DisplayRouter
public function optionsSummary(&$categories, &$options) {
parent::optionsSummary($categories, $options);
$categories['page'] = array(
$categories['page'] = [
'title' => $this->t('Page settings'),
'column' => 'second',
'build' => array(
'build' => [
'#weight' => -10,
),
);
],
];
$path = strip_tags($this->getOption('path'));
@ -382,11 +421,11 @@ abstract class PathPluginBase extends DisplayPluginBase implements DisplayRouter
$path = '/' . $path;
}
$options['path'] = array(
$options['path'] = [
'category' => 'page',
'title' => $this->t('Path'),
'value' => views_ui_truncate($path, 24),
);
];
}
/**
@ -398,17 +437,17 @@ abstract class PathPluginBase extends DisplayPluginBase implements DisplayRouter
switch ($form_state->get('section')) {
case 'path':
$form['#title'] .= $this->t('The menu path or URL of this view');
$form['path'] = array(
$form['path'] = [
'#type' => 'textfield',
'#title' => $this->t('Path'),
'#description' => $this->t('This view will be displayed by visiting this path on your site. You may use "%" in your URL to represent values that will be used for contextual filters: For example, "node/%/feed". If needed you can even specify named route parameters like taxonomy/term/%taxonomy_term'),
'#default_value' => $this->getOption('path'),
'#field_prefix' => '<span dir="ltr">' . $this->url('<none>', [], ['absolute' => TRUE]),
'#field_suffix' => '</span>&lrm;',
'#attributes' => array('dir' => LanguageInterface::DIRECTION_LTR),
'#attributes' => ['dir' => LanguageInterface::DIRECTION_LTR],
// Account for the leading backslash.
'#maxlength' => 254,
);
];
break;
}
}
@ -451,7 +490,7 @@ abstract class PathPluginBase extends DisplayPluginBase implements DisplayRouter
* A list of error strings.
*/
protected function validatePath($path) {
$errors = array();
$errors = [];
if (strpos($path, '%') === 0) {
$errors[] = $this->t('"%" may not be used for the first segment of a path.');
}
@ -518,7 +557,7 @@ abstract class PathPluginBase extends DisplayPluginBase implements DisplayRouter
* {@inheritdoc}
*/
public function getAlteredRouteNames() {
return $this->state->get('views.view_route_names') ?: array();
return $this->state->get('views.view_route_names') ?: [];
}
/**

View file

@ -26,13 +26,13 @@ abstract class ExposedFormPluginBase extends PluginBase implements CacheableDepe
*/
protected function defineOptions() {
$options = parent::defineOptions();
$options['submit_button'] = array('default' => $this->t('Apply'));
$options['reset_button'] = array('default' => FALSE);
$options['reset_button_label'] = array('default' => $this->t('Reset'));
$options['exposed_sorts_label'] = array('default' => $this->t('Sort by'));
$options['expose_sort_order'] = array('default' => TRUE);
$options['sort_asc_label'] = array('default' => $this->t('Asc'));
$options['sort_desc_label'] = array('default' => $this->t('Desc'));
$options['submit_button'] = ['default' => $this->t('Apply')];
$options['reset_button'] = ['default' => FALSE];
$options['reset_button_label'] = ['default' => $this->t('Reset')];
$options['exposed_sorts_label'] = ['default' => $this->t('Sort by')];
$options['expose_sort_order'] = ['default' => TRUE];
$options['sort_asc_label'] = ['default' => $this->t('Asc')];
$options['sort_desc_label'] = ['default' => $this->t('Desc')];
return $options;
}
@ -41,69 +41,69 @@ abstract class ExposedFormPluginBase extends PluginBase implements CacheableDepe
*/
public function buildOptionsForm(&$form, FormStateInterface $form_state) {
parent::buildOptionsForm($form, $form_state);
$form['submit_button'] = array(
$form['submit_button'] = [
'#type' => 'textfield',
'#title' => $this->t('Submit button text'),
'#default_value' => $this->options['submit_button'],
'#required' => TRUE,
);
];
$form['reset_button'] = array(
$form['reset_button'] = [
'#type' => 'checkbox',
'#title' => $this->t('Include reset button (resets all applied exposed filters)'),
'#default_value' => $this->options['reset_button'],
);
];
$form['reset_button_label'] = array(
$form['reset_button_label'] = [
'#type' => 'textfield',
'#title' => $this->t('Reset button label'),
'#description' => $this->t('Text to display in the reset button of the exposed form.'),
'#default_value' => $this->options['reset_button_label'],
'#required' => TRUE,
'#states' => array(
'invisible' => array(
'input[name="exposed_form_options[reset_button]"]' => array('checked' => FALSE),
),
),
);
'#states' => [
'invisible' => [
'input[name="exposed_form_options[reset_button]"]' => ['checked' => FALSE],
],
],
];
$form['exposed_sorts_label'] = array(
$form['exposed_sorts_label'] = [
'#type' => 'textfield',
'#title' => $this->t('Exposed sorts label'),
'#default_value' => $this->options['exposed_sorts_label'],
'#required' => TRUE,
);
];
$form['expose_sort_order'] = array(
$form['expose_sort_order'] = [
'#type' => 'checkbox',
'#title' => $this->t('Allow people to choose the sort order'),
'#description' => $this->t('If sort order is not exposed, the sort criteria settings for each sort will determine its order.'),
'#default_value' => $this->options['expose_sort_order'],
);
];
$form['sort_asc_label'] = array(
$form['sort_asc_label'] = [
'#type' => 'textfield',
'#title' => $this->t('Label for ascending sort'),
'#default_value' => $this->options['sort_asc_label'],
'#required' => TRUE,
'#states' => array(
'visible' => array(
'input[name="exposed_form_options[expose_sort_order]"]' => array('checked' => TRUE),
),
),
);
'#states' => [
'visible' => [
'input[name="exposed_form_options[expose_sort_order]"]' => ['checked' => TRUE],
],
],
];
$form['sort_desc_label'] = array(
$form['sort_desc_label'] = [
'#type' => 'textfield',
'#title' => $this->t('Label for descending sort'),
'#default_value' => $this->options['sort_desc_label'],
'#required' => TRUE,
'#states' => array(
'visible' => array(
'input[name="exposed_form_options[expose_sort_order]"]' => array('checked' => TRUE),
),
),
);
'#states' => [
'visible' => [
'input[name="exposed_form_options[expose_sort_order]"]' => ['checked' => TRUE],
],
],
];
}
/**
@ -133,9 +133,15 @@ abstract class ExposedFormPluginBase extends PluginBase implements CacheableDepe
}
$form = \Drupal::formBuilder()->buildForm('\Drupal\views\Form\ViewsExposedForm', $form_state);
$errors = $form_state->getErrors();
// If the exposed form had errors, do not build the view.
if (!empty($errors)) {
$this->view->build_info['abort'] = TRUE;
}
if (!$this->view->display_handler->displaysExposed() || (!$block && $this->view->display_handler->getOption('exposed_block'))) {
return array();
return [];
}
else {
return $form;
@ -147,19 +153,19 @@ abstract class ExposedFormPluginBase extends PluginBase implements CacheableDepe
*/
public function query() {
$view = $this->view;
$exposed_data = isset($view->exposed_data) ? $view->exposed_data : array();
$exposed_data = isset($view->exposed_data) ? $view->exposed_data : [];
$sort_by = isset($exposed_data['sort_by']) ? $exposed_data['sort_by'] : NULL;
if (!empty($sort_by)) {
// Make sure the original order of sorts is preserved
// (e.g. a sticky sort is often first)
if (isset($view->sort[$sort_by])) {
$view->query->orderby = array();
$view->query->orderby = [];
foreach ($view->sort as $key => $sort) {
if (!$sort->isExposed()) {
$sort->query();
}
elseif ($key == $sort_by) {
if (isset($exposed_data['sort_order']) && in_array($exposed_data['sort_order'], array('ASC', 'DESC'))) {
if (isset($exposed_data['sort_order']) && in_array($exposed_data['sort_order'], ['ASC', 'DESC'])) {
$sort->options['order'] = $exposed_data['sort_order'];
}
$sort->setRelationship();
@ -199,7 +205,7 @@ abstract class ExposedFormPluginBase extends PluginBase implements CacheableDepe
}
// Check if there is exposed sorts for this view
$exposed_sorts = array();
$exposed_sorts = [];
foreach ($this->view->sort as $id => $handler) {
if ($handler->canExpose() && $handler->isExposed()) {
$exposed_sorts[$id] = Html::escape($handler->options['expose']['label']);
@ -207,15 +213,15 @@ abstract class ExposedFormPluginBase extends PluginBase implements CacheableDepe
}
if (count($exposed_sorts)) {
$form['sort_by'] = array(
$form['sort_by'] = [
'#type' => 'select',
'#options' => $exposed_sorts,
'#title' => $this->options['exposed_sorts_label'],
);
$sort_order = array(
];
$sort_order = [
'ASC' => $this->options['sort_asc_label'],
'DESC' => $this->options['sort_desc_label'],
);
];
$user_input = $form_state->getUserInput();
if (isset($user_input['sort_by']) && isset($this->view->sort[$user_input['sort_by']])) {
$default_sort_order = $this->view->sort[$user_input['sort_by']]->options['order'];
@ -232,22 +238,22 @@ abstract class ExposedFormPluginBase extends PluginBase implements CacheableDepe
}
if ($this->options['expose_sort_order']) {
$form['sort_order'] = array(
$form['sort_order'] = [
'#type' => 'select',
'#options' => $sort_order,
'#title' => $this->t('Order', array(), array('context' => 'Sort order')),
'#title' => $this->t('Order', [], ['context' => 'Sort order']),
'#default_value' => $default_sort_order,
);
];
}
$form['submit']['#weight'] = 10;
}
if (!empty($this->options['reset_button'])) {
$form['actions']['reset'] = array(
$form['actions']['reset'] = [
'#value' => $this->options['reset_button_label'],
'#type' => 'submit',
'#weight' => 10,
);
];
// Get an array of exposed filters, keyed by identifier option.
$exposed_filters = [];
@ -323,7 +329,7 @@ abstract class ExposedFormPluginBase extends PluginBase implements CacheableDepe
}
else {
$form_state->setRebuild();
$this->view->exposed_data = array();
$this->view->exposed_data = [];
}
$form_state->setRedirect('<current>');

View file

@ -21,28 +21,28 @@ class InputRequired extends ExposedFormPluginBase {
protected function defineOptions() {
$options = parent::defineOptions();
$options['text_input_required'] = array('default' => $this->t('Select any filter and click on Apply to see results'));
$options['text_input_required_format'] = array('default' => NULL);
$options['text_input_required'] = ['default' => $this->t('Select any filter and click on Apply to see results')];
$options['text_input_required_format'] = ['default' => NULL];
return $options;
}
public function buildOptionsForm(&$form, FormStateInterface $form_state) {
parent::buildOptionsForm($form, $form_state);
$form['text_input_required'] = array(
$form['text_input_required'] = [
'#type' => 'text_format',
'#title' => $this->t('Text on demand'),
'#description' => $this->t('Text to display instead of results until the user selects and applies an exposed filter.'),
'#default_value' => $this->options['text_input_required'],
'#format' => isset($this->options['text_input_required_format']) ? $this->options['text_input_required_format'] : filter_default_format(),
'#editor' => FALSE,
);
];
}
public function submitOptionsForm(&$form, FormStateInterface $form_state) {
$exposed_form_options = $form_state->getValue('exposed_form_options');
$form_state->setValue(array('exposed_form_options', 'text_input_required_format'), $exposed_form_options['text_input_required']['format']);
$form_state->setValue(array('exposed_form_options', 'text_input_required'), $exposed_form_options['text_input_required']['value']);
$form_state->setValue(['exposed_form_options', 'text_input_required_format'], $exposed_form_options['text_input_required']['format']);
$form_state->setValue(['exposed_form_options', 'text_input_required'], $exposed_form_options['text_input_required']['value']);
parent::submitOptionsForm($form, $form_state);
}
@ -72,7 +72,7 @@ class InputRequired extends ExposedFormPluginBase {
// text to display instead of results until the user selects and applies
// an exposed filter.
if (!$this->exposedFilterApplied()) {
$options = array(
$options = [
'id' => 'area',
'table' => 'views',
'field' => 'area',
@ -88,14 +88,14 @@ class InputRequired extends ExposedFormPluginBase {
'value' => $this->options['text_input_required'],
'format' => $this->options['text_input_required_format'],
],
);
];
$handler = Views::handlerManager('area')->getHandler($options);
$handler->init($this->view, $this->displayHandler, $options);
$this->displayHandler->handlers['empty'] = array(
$this->displayHandler->handlers['empty'] = [
'area' => $handler,
);
];
// Override the existing empty result message (if applicable).
$this->displayHandler->setOption('empty', array('text' => $options));
$this->displayHandler->setOption('empty', ['text' => $options]);
}
}
@ -104,7 +104,7 @@ class InputRequired extends ExposedFormPluginBase {
// We return with no query; this will force the empty text.
$this->view->built = TRUE;
$this->view->executed = TRUE;
$this->view->result = array();
$this->view->result = [];
}
else {
parent::query();

View file

@ -34,10 +34,10 @@ class Boolean extends FieldPluginBase {
*/
protected function defineOptions() {
$options = parent::defineOptions();
$options['type'] = array('default' => 'yes-no');
$options['type_custom_true'] = array('default' => '');
$options['type_custom_false'] = array('default' => '');
$options['not'] = array('default' => FALSE);
$options['type'] = ['default' => 'yes-no'];
$options['type_custom_true'] = ['default' => ''];
$options['type_custom_false'] = ['default' => ''];
$options['not'] = ['default' => FALSE];
return $options;
}
@ -48,16 +48,16 @@ class Boolean extends FieldPluginBase {
public function init(ViewExecutable $view, DisplayPluginBase $display, array &$options = NULL) {
parent::init($view, $display, $options);
$default_formats = array(
'yes-no' => array(t('Yes'), $this->t('No')),
'true-false' => array(t('True'), $this->t('False')),
'on-off' => array(t('On'), $this->t('Off')),
'enabled-disabled' => array(t('Enabled'), $this->t('Disabled')),
'boolean' => array(1, 0),
'unicode-yes-no' => array('✔', '✖'),
);
$output_formats = isset($this->definition['output formats']) ? $this->definition['output formats'] : array();
$custom_format = array('custom' => array(t('Custom')));
$default_formats = [
'yes-no' => [t('Yes'), $this->t('No')],
'true-false' => [t('True'), $this->t('False')],
'on-off' => [t('On'), $this->t('Off')],
'enabled-disabled' => [t('Enabled'), $this->t('Disabled')],
'boolean' => [1, 0],
'unicode-yes-no' => ['✔', '✖'],
];
$output_formats = isset($this->definition['output formats']) ? $this->definition['output formats'] : [];
$custom_format = ['custom' => [t('Custom')]];
$this->formats = array_merge($default_formats, $output_formats, $custom_format);
}
@ -69,38 +69,38 @@ class Boolean extends FieldPluginBase {
$options[$key] = implode('/', $item);
}
$form['type'] = array(
$form['type'] = [
'#type' => 'select',
'#title' => $this->t('Output format'),
'#options' => $options,
'#default_value' => $this->options['type'],
);
$form['type_custom_true'] = array(
];
$form['type_custom_true'] = [
'#type' => 'textfield',
'#title' => $this->t('Custom output for TRUE'),
'#default_value' => $this->options['type_custom_true'],
'#states' => array(
'visible' => array(
'select[name="options[type]"]' => array('value' => 'custom'),
),
),
);
$form['type_custom_false'] = array(
'#states' => [
'visible' => [
'select[name="options[type]"]' => ['value' => 'custom'],
],
],
];
$form['type_custom_false'] = [
'#type' => 'textfield',
'#title' => $this->t('Custom output for FALSE'),
'#default_value' => $this->options['type_custom_false'],
'#states' => array(
'visible' => array(
'select[name="options[type]"]' => array('value' => 'custom'),
),
),
);
$form['not'] = array(
'#states' => [
'visible' => [
'select[name="options[type]"]' => ['value' => 'custom'],
],
],
];
$form['not'] = [
'#type' => 'checkbox',
'#title' => $this->t('Reverse'),
'#description' => $this->t('If checked, true will be displayed as false.'),
'#default_value' => $this->options['not'],
);
];
parent::buildOptionsForm($form, $form_state);
}

View file

@ -28,7 +28,7 @@ class Counter extends FieldPluginBase {
*/
protected function defineOptions() {
$options = parent::defineOptions();
$options['counter_start'] = array('default' => 1);
$options['counter_start'] = ['default' => 1];
return $options;
}
@ -36,13 +36,13 @@ class Counter extends FieldPluginBase {
* {@inheritdoc}
*/
public function buildOptionsForm(&$form, FormStateInterface $form_state) {
$form['counter_start'] = array(
$form['counter_start'] = [
'#type' => 'textfield',
'#title' => $this->t('Starting value'),
'#default_value' => $this->options['counter_start'],
'#description' => $this->t('Specify the number the counter should start at.'),
'#size' => 2,
);
];
parent::buildOptionsForm($form, $form_state);
}

View file

@ -37,8 +37,8 @@ class Custom extends FieldPluginBase {
$options = parent::defineOptions();
// Override the alter text option to always alter the text.
$options['alter']['contains']['alter_text'] = array('default' => TRUE);
$options['hide_alter_empty'] = array('default' => FALSE);
$options['alter']['contains']['alter_text'] = ['default' => TRUE];
$options['hide_alter_empty'] = ['default' => FALSE];
return $options;
}
@ -52,7 +52,7 @@ class Custom extends FieldPluginBase {
unset($form['alter']['alter_text']);
unset($form['alter']['text']['#states']);
unset($form['alter']['help']['#states']);
$form['#pre_render'][] = array($this, 'preRenderCustomForm');
$form['#pre_render'][] = [$this, 'preRenderCustomForm'];
}
/**

View file

@ -71,9 +71,9 @@ class Date extends FieldPluginBase {
protected function defineOptions() {
$options = parent::defineOptions();
$options['date_format'] = array('default' => 'small');
$options['custom_date_format'] = array('default' => '');
$options['timezone'] = array('default' => '');
$options['date_format'] = ['default' => 'small'];
$options['custom_date_format'] = ['default' => ''];
$options['timezone'] = ['default' => ''];
return $options;
}
@ -83,15 +83,15 @@ class Date extends FieldPluginBase {
*/
public function buildOptionsForm(&$form, FormStateInterface $form_state) {
$date_formats = array();
$date_formats = [];
foreach ($this->dateFormatStorage->loadMultiple() as $machine_name => $value) {
$date_formats[$machine_name] = $this->t('@name format: @date', array('@name' => $value->label(), '@date' => $this->dateFormatter->format(REQUEST_TIME, $machine_name)));
$date_formats[$machine_name] = $this->t('@name format: @date', ['@name' => $value->label(), '@date' => $this->dateFormatter->format(REQUEST_TIME, $machine_name)]);
}
$form['date_format'] = array(
$form['date_format'] = [
'#type' => 'select',
'#title' => $this->t('Date format'),
'#options' => $date_formats + array(
'#options' => $date_formats + [
'custom' => $this->t('Custom'),
'raw time ago' => $this->t('Time ago'),
'time ago' => $this->t('Time ago (with "ago" appended)'),
@ -100,32 +100,32 @@ class Date extends FieldPluginBase {
'raw time span' => $this->t('Time span (future dates have "-" prepended)'),
'inverse time span' => $this->t('Time span (past dates have "-" prepended)'),
'time span' => $this->t('Time span (with "ago/hence" appended)'),
),
],
'#default_value' => isset($this->options['date_format']) ? $this->options['date_format'] : 'small',
);
$form['custom_date_format'] = array(
];
$form['custom_date_format'] = [
'#type' => 'textfield',
'#title' => $this->t('Custom date format'),
'#description' => $this->t('If "Custom", see <a href="http://us.php.net/manual/en/function.date.php" target="_blank">the PHP docs</a> for date formats. Otherwise, enter the number of different time units to display, which defaults to 2.'),
'#default_value' => isset($this->options['custom_date_format']) ? $this->options['custom_date_format'] : '',
);
];
// Setup #states for all possible date_formats on the custom_date_format form element.
foreach (array('custom', 'raw time ago', 'time ago', 'raw time hence', 'time hence', 'raw time span', 'time span', 'raw time span', 'inverse time span', 'time span') as $custom_date_possible) {
$form['custom_date_format']['#states']['visible'][] = array(
':input[name="options[date_format]"]' => array('value' => $custom_date_possible),
);
foreach (['custom', 'raw time ago', 'time ago', 'raw time hence', 'time hence', 'raw time span', 'time span', 'raw time span', 'inverse time span', 'time span'] as $custom_date_possible) {
$form['custom_date_format']['#states']['visible'][] = [
':input[name="options[date_format]"]' => ['value' => $custom_date_possible],
];
}
$form['timezone'] = array(
$form['timezone'] = [
'#type' => 'select',
'#title' => $this->t('Timezone'),
'#description' => $this->t('Timezone to be used for date output.'),
'#options' => array('' => $this->t('- Default site/user timezone -')) + system_time_zones(FALSE),
'#options' => ['' => $this->t('- Default site/user timezone -')] + system_time_zones(FALSE),
'#default_value' => $this->options['timezone'],
);
foreach (array_merge(array('custom'), array_keys($date_formats)) as $timezone_date_formats) {
$form['timezone']['#states']['visible'][] = array(
':input[name="options[date_format]"]' => array('value' => $timezone_date_formats),
);
];
foreach (array_merge(['custom'], array_keys($date_formats)) as $timezone_date_formats) {
$form['timezone']['#states']['visible'][] = [
':input[name="options[date_format]"]' => ['value' => $timezone_date_formats],
];
}
parent::buildOptionsForm($form, $form_state);
@ -137,7 +137,7 @@ class Date extends FieldPluginBase {
public function render(ResultRow $values) {
$value = $this->getValue($values);
$format = $this->options['date_format'];
if (in_array($format, array('custom', 'raw time ago', 'time ago', 'raw time hence', 'time hence', 'raw time span', 'time span', 'raw time span', 'inverse time span', 'time span'))) {
if (in_array($format, ['custom', 'raw time ago', 'time ago', 'raw time hence', 'time hence', 'raw time span', 'time span', 'raw time span', 'inverse time span', 'time span'])) {
$custom_format = $this->options['custom_date_format'];
}
@ -146,26 +146,26 @@ class Date extends FieldPluginBase {
$time_diff = REQUEST_TIME - $value; // will be positive for a datetime in the past (ago), and negative for a datetime in the future (hence)
switch ($format) {
case 'raw time ago':
return $this->dateFormatter->formatTimeDiffSince($value, array('granularity' => is_numeric($custom_format) ? $custom_format : 2));
return $this->dateFormatter->formatTimeDiffSince($value, ['granularity' => is_numeric($custom_format) ? $custom_format : 2]);
case 'time ago':
return $this->t('%time ago', array('%time' => $this->dateFormatter->formatTimeDiffSince($value, array('granularity' => is_numeric($custom_format) ? $custom_format : 2))));
return $this->t('%time ago', ['%time' => $this->dateFormatter->formatTimeDiffSince($value, ['granularity' => is_numeric($custom_format) ? $custom_format : 2])]);
case 'raw time hence':
return $this->dateFormatter->formatTimeDiffUntil($value, array('granularity' => is_numeric($custom_format) ? $custom_format : 2));
return $this->dateFormatter->formatTimeDiffUntil($value, ['granularity' => is_numeric($custom_format) ? $custom_format : 2]);
case 'time hence':
return $this->t('%time hence', array('%time' => $this->dateFormatter->formatTimeDiffUntil($value, array('granularity' => is_numeric($custom_format) ? $custom_format : 2))));
return $this->t('%time hence', ['%time' => $this->dateFormatter->formatTimeDiffUntil($value, ['granularity' => is_numeric($custom_format) ? $custom_format : 2])]);
case 'raw time span':
return ($time_diff < 0 ? '-' : '') . $this->dateFormatter->formatTimeDiffSince($value, array('strict' => FALSE, 'granularity' => is_numeric($custom_format) ? $custom_format : 2));
return ($time_diff < 0 ? '-' : '') . $this->dateFormatter->formatTimeDiffSince($value, ['strict' => FALSE, 'granularity' => is_numeric($custom_format) ? $custom_format : 2]);
case 'inverse time span':
return ($time_diff > 0 ? '-' : '') . $this->dateFormatter->formatTimeDiffSince($value, array('strict' => FALSE, 'granularity' => is_numeric($custom_format) ? $custom_format : 2));
return ($time_diff > 0 ? '-' : '') . $this->dateFormatter->formatTimeDiffSince($value, ['strict' => FALSE, 'granularity' => is_numeric($custom_format) ? $custom_format : 2]);
case 'time span':
$time = $this->dateFormatter->formatTimeDiffSince($value, array('strict' => FALSE, 'granularity' => is_numeric($custom_format) ? $custom_format : 2));
return ($time_diff < 0) ? $this->t('%time hence', array('%time' => $time)) : $this->t('%time ago', array('%time' => $time));
$time = $this->dateFormatter->formatTimeDiffSince($value, ['strict' => FALSE, 'granularity' => is_numeric($custom_format) ? $custom_format : 2]);
return ($time_diff < 0) ? $this->t('%time hence', ['%time' => $time]) : $this->t('%time ago', ['%time' => $time]);
case 'custom':
if ($custom_format == 'r') {

View file

@ -20,10 +20,10 @@ class Dropbutton extends Links {
$links = $this->getLinks();
if (!empty($links)) {
return array(
return [
'#type' => 'dropbutton',
'#links' => $links,
);
];
}
else {
return '';

File diff suppressed because it is too large Load diff

View file

@ -23,7 +23,7 @@ class EntityLabel extends FieldPluginBase {
*
* @var array
*/
protected $loadedReferencers = array();
protected $loadedReferencers = [];
/**
* EntityManager class.
@ -75,7 +75,7 @@ class EntityLabel extends FieldPluginBase {
*/
protected function defineOptions() {
$options = parent::defineOptions();
$options['link_to_entity'] = array('default' => FALSE);
$options['link_to_entity'] = ['default' => FALSE];
return $options;
}
@ -83,12 +83,12 @@ class EntityLabel extends FieldPluginBase {
* {@inheritdoc}
*/
public function buildOptionsForm(&$form, FormStateInterface $form_state) {
$form['link_to_entity'] = array(
$form['link_to_entity'] = [
'#title' => $this->t('Link to entity'),
'#description' => $this->t('Make entity label a link to entity page.'),
'#type' => 'checkbox',
'#default_value' => !empty($this->options['link_to_entity']),
);
];
parent::buildOptionsForm($form, $form_state);
}
@ -128,7 +128,7 @@ class EntityLabel extends FieldPluginBase {
public function preRender(&$values) {
parent::preRender($values);
$entity_ids_per_type = array();
$entity_ids_per_type = [];
foreach ($values as $value) {
if ($type = $this->getValue($value, 'type')) {
$entity_ids_per_type[$type][] = $this->getValue($value);

View file

@ -83,9 +83,9 @@ class EntityOperations extends FieldPluginBase {
public function defineOptions() {
$options = parent::defineOptions();
$options['destination'] = array(
$options['destination'] = [
'default' => TRUE,
);
];
return $options;
}
@ -96,12 +96,12 @@ class EntityOperations extends FieldPluginBase {
public function buildOptionsForm(&$form, FormStateInterface $form_state) {
parent::buildOptionsForm($form, $form_state);
$form['destination'] = array(
$form['destination'] = [
'#type' => 'checkbox',
'#title' => $this->t('Include destination'),
'#description' => $this->t('Include a <code>destination</code> parameter in the link to return the user to the original view upon completing the link action.'),
'#default_value' => $this->options['destination'],
);
];
}
/**
@ -113,15 +113,15 @@ class EntityOperations extends FieldPluginBase {
if ($this->options['destination']) {
foreach ($operations as &$operation) {
if (!isset($operation['query'])) {
$operation['query'] = array();
$operation['query'] = [];
}
$operation['query'] += $this->getDestinationArray();
}
}
$build = array(
$build = [
'#type' => 'operations',
'#links' => $operations,
);
];
return $build;
}

File diff suppressed because it is too large Load diff

View file

@ -265,6 +265,6 @@ interface FieldHandlerInterface extends ViewsHandlerInterface {
* is safe it will be wrapped in an object that implements
* MarkupInterface. If it is empty or unsafe it will be a string.
*/
function theme(ResultRow $values);
public function theme(ResultRow $values);
}

View file

@ -20,7 +20,7 @@ class FileSize extends FieldPluginBase {
protected function defineOptions() {
$options = parent::defineOptions();
$options['file_size_display'] = array('default' => 'formatted');
$options['file_size_display'] = ['default' => 'formatted'];
return $options;
}
@ -30,14 +30,14 @@ class FileSize extends FieldPluginBase {
*/
public function buildOptionsForm(&$form, FormStateInterface $form_state) {
parent::buildOptionsForm($form, $form_state);
$form['file_size_display'] = array(
$form['file_size_display'] = [
'#title' => $this->t('File size display'),
'#type' => 'select',
'#options' => array(
'#options' => [
'formatted' => $this->t('Formatted (in KB or MB)'),
'bytes' => $this->t('Raw bytes'),
),
);
],
];
}
/**

View file

@ -19,7 +19,7 @@ class LanguageField extends FieldPluginBase {
*/
protected function defineOptions() {
$options = parent::defineOptions();
$options['native_language'] = array('default' => FALSE);
$options['native_language'] = ['default' => FALSE];
return $options;
}
@ -29,11 +29,11 @@ class LanguageField extends FieldPluginBase {
*/
public function buildOptionsForm(&$form, FormStateInterface $form_state) {
parent::buildOptionsForm($form, $form_state);
$form['native_language'] = array(
$form['native_language'] = [
'#title' => $this->t('Display in native language'),
'#type' => 'checkbox',
'#default_value' => $this->options['native_language'],
);
];
}
/**

Some files were not shown because too many files have changed in this diff Show more