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

@ -32,12 +32,12 @@ class ContextualController implements ContainerAwareInterface {
throw new BadRequestHttpException(t('No contextual ids specified.'));
}
$rendered = array();
$rendered = [];
foreach ($ids as $id) {
$element = array(
$element = [
'#type' => 'contextual_links',
'#contextual_links' => _contextual_id_to_links($id),
);
];
$rendered[$id] = $this->container->get('renderer')->renderRoot($element);
}

View file

@ -18,19 +18,19 @@ class ContextualLinks extends RenderElement {
*/
public function getInfo() {
$class = get_class($this);
return array(
'#pre_render' => array(
array($class, 'preRenderLinks'),
),
return [
'#pre_render' => [
[$class, 'preRenderLinks'],
],
'#theme' => 'links__contextual',
'#links' => array(),
'#attributes' => array('class' => array('contextual-links')),
'#attached' => array(
'library' => array(
'#links' => [],
'#attributes' => ['class' => ['contextual-links']],
'#attached' => [
'library' => [
'contextual/drupal.contextual-links',
),
),
);
],
],
];
}
/**
@ -60,26 +60,26 @@ class ContextualLinks extends RenderElement {
*/
public static function preRenderLinks(array $element) {
// Retrieve contextual menu links.
$items = array();
$items = [];
$contextual_links_manager = static::contextualLinkManager();
foreach ($element['#contextual_links'] as $group => $args) {
$args += array(
'route_parameters' => array(),
'metadata' => array(),
);
$args += [
'route_parameters' => [],
'metadata' => [],
];
$items += $contextual_links_manager->getContextualLinksArrayByGroup($group, $args['route_parameters'], $args['metadata']);
}
// Transform contextual links into parameters suitable for links.html.twig.
$links = array();
$links = [];
foreach ($items as $class => $item) {
$class = Html::getClass($class);
$links[$class] = array(
$links[$class] = [
'title' => $item['title'],
'url' => Url::fromRoute(isset($item['route_name']) ? $item['route_name'] : '', isset($item['route_parameters']) ? $item['route_parameters'] : []),
);
];
}
$element['#links'] = $links;

View file

@ -18,12 +18,12 @@ class ContextualLinksPlaceholder extends RenderElement {
*/
public function getInfo() {
$class = get_class($this);
return array(
'#pre_render' => array(
array($class, 'preRenderPlaceholder'),
),
return [
'#pre_render' => [
[$class, 'preRenderPlaceholder'],
],
'#id' => NULL,
);
];
}
/**

View file

@ -35,8 +35,8 @@ class ContextualLinks extends FieldPluginBase {
protected function defineOptions() {
$options = parent::defineOptions();
$options['fields'] = array('default' => array());
$options['destination'] = array('default' => 1);
$options['fields'] = ['default' => []];
$options['destination'] = ['default' => 1];
return $options;
}
@ -48,23 +48,23 @@ class ContextualLinks extends FieldPluginBase {
$all_fields = $this->view->display_handler->getFieldLabels();
// Offer to include only those fields that follow this one.
$field_options = array_slice($all_fields, 0, array_search($this->options['id'], array_keys($all_fields)));
$form['fields'] = array(
$form['fields'] = [
'#type' => 'checkboxes',
'#title' => $this->t('Fields'),
'#description' => $this->t('Fields to be included as contextual links.'),
'#options' => $field_options,
'#default_value' => $this->options['fields'],
);
$form['destination'] = array(
];
$form['destination'] = [
'#type' => 'select',
'#title' => $this->t('Include destination'),
'#description' => $this->t('Include a "destination" parameter in the link to return the user to the original view upon completing the contextual action.'),
'#options' => array(
'#options' => [
'0' => $this->t('No'),
'1' => $this->t('Yes'),
),
],
'#default_value' => $this->options['destination'],
);
];
}
/**
@ -93,7 +93,7 @@ class ContextualLinks extends FieldPluginBase {
* @see contextual_contextual_links_view_alter()
*/
public function render(ResultRow $values) {
$links = array();
$links = [];
foreach ($this->options['fields'] as $field) {
$rendered_field = $this->view->style_plugin->getField($values->index, $field);
if (empty($rendered_field)) {
@ -109,13 +109,13 @@ class ContextualLinks extends FieldPluginBase {
}
if (!empty($title) && !empty($path)) {
// Make sure that tokens are replaced for this paths as well.
$tokens = $this->getRenderTokens(array());
$tokens = $this->getRenderTokens([]);
$path = strip_tags(Html::decodeEntities(strtr($path, $tokens)));
$links[$field] = array(
$links[$field] = [
'href' => $path,
'title' => $title,
);
];
if (!empty($this->options['destination'])) {
$links[$field]['query'] = $this->getDestinationArray();
}
@ -124,20 +124,20 @@ class ContextualLinks extends FieldPluginBase {
// Renders a contextual links placeholder.
if (!empty($links)) {
$contextual_links = array(
'contextual' => array(
$contextual_links = [
'contextual' => [
'',
array(),
array(
[],
[
'contextual-views-field-links' => UrlHelper::encodePath(Json::encode($links)),
)
)
);
]
]
];
$element = array(
$element = [
'#type' => 'contextual_links_placeholder',
'#id' => _contextual_links_to_id($contextual_links),
);
];
return drupal_render($element);
}
else {

View file

@ -42,20 +42,20 @@ class ContextualDynamicContextTest extends WebTestBase {
*
* @var array
*/
public static $modules = array('contextual', 'node', 'views', 'views_ui', 'language', 'menu_test');
public static $modules = ['contextual', 'node', 'views', 'views_ui', 'language', 'menu_test'];
protected function setUp() {
parent::setUp();
$this->drupalCreateContentType(array('type' => 'page', 'name' => 'Basic page'));
$this->drupalCreateContentType(array('type' => 'article', 'name' => 'Article'));
$this->drupalCreateContentType(['type' => 'page', 'name' => 'Basic page']);
$this->drupalCreateContentType(['type' => 'article', 'name' => 'Article']);
ConfigurableLanguage::createFromLangcode('it')->save();
$this->rebuildContainer();
$this->editorUser = $this->drupalCreateUser(array('access content', 'access contextual links', 'edit any article content'));
$this->authenticatedUser = $this->drupalCreateUser(array('access content', 'access contextual links'));
$this->anonymousUser = $this->drupalCreateUser(array('access content'));
$this->editorUser = $this->drupalCreateUser(['access content', 'access contextual links', 'edit any article content']);
$this->authenticatedUser = $this->drupalCreateUser(['access content', 'access contextual links']);
$this->anonymousUser = $this->drupalCreateUser(['access content']);
}
/**
@ -64,16 +64,16 @@ class ContextualDynamicContextTest extends WebTestBase {
* Ensures that contextual link placeholders always exist, even if the user is
* not allowed to use contextual links.
*/
function testDifferentPermissions() {
public function testDifferentPermissions() {
$this->drupalLogin($this->editorUser);
// Create three nodes in the following order:
// - An article, which should be user-editable.
// - A page, which should not be user-editable.
// - A second article, which should also be user-editable.
$node1 = $this->drupalCreateNode(array('type' => 'article', 'promote' => 1));
$node2 = $this->drupalCreateNode(array('type' => 'page', 'promote' => 1));
$node3 = $this->drupalCreateNode(array('type' => 'article', 'promote' => 1));
$node1 = $this->drupalCreateNode(['type' => 'article', 'promote' => 1]);
$node2 = $this->drupalCreateNode(['type' => 'page', 'promote' => 1]);
$node3 = $this->drupalCreateNode(['type' => 'article', 'promote' => 1]);
// Now, on the front page, all article nodes should have contextual links
// placeholders, as should the view that contains them.
@ -89,7 +89,7 @@ class ContextualDynamicContextTest extends WebTestBase {
for ($i = 0; $i < count($ids); $i++) {
$this->assertContextualLinkPlaceHolder($ids[$i]);
}
$this->renderContextualLinks(array(), 'node');
$this->renderContextualLinks([], 'node');
$this->assertResponse(400);
$this->assertRaw('No contextual ids specified.');
$response = $this->renderContextualLinks($ids, 'node');
@ -112,7 +112,7 @@ class ContextualDynamicContextTest extends WebTestBase {
for ($i = 0; $i < count($ids); $i++) {
$this->assertContextualLinkPlaceHolder($ids[$i]);
}
$this->renderContextualLinks(array(), 'node');
$this->renderContextualLinks([], 'node');
$this->assertResponse(400);
$this->assertRaw('No contextual ids specified.');
$response = $this->renderContextualLinks($ids, 'node');
@ -129,7 +129,7 @@ class ContextualDynamicContextTest extends WebTestBase {
for ($i = 0; $i < count($ids); $i++) {
$this->assertNoContextualLinkPlaceHolder($ids[$i]);
}
$this->renderContextualLinks(array(), 'node');
$this->renderContextualLinks([], 'node');
$this->assertResponse(403);
$this->renderContextualLinks($ids, 'node');
$this->assertResponse(403);
@ -150,7 +150,7 @@ class ContextualDynamicContextTest extends WebTestBase {
* The result of the assertion.
*/
protected function assertContextualLinkPlaceHolder($id) {
return $this->assertRaw('<div' . new Attribute(array('data-contextual-id' => $id)) . '></div>', format_string('Contextual link placeholder with id @id exists.', array('@id' => $id)));
return $this->assertRaw('<div' . new Attribute(['data-contextual-id' => $id]) . '></div>', format_string('Contextual link placeholder with id @id exists.', ['@id' => $id]));
}
/**
@ -163,7 +163,7 @@ class ContextualDynamicContextTest extends WebTestBase {
* The result of the assertion.
*/
protected function assertNoContextualLinkPlaceHolder($id) {
return $this->assertNoRaw('<div' . new Attribute(array('data-contextual-id' => $id)) . '></div>', format_string('Contextual link placeholder with id @id does not exist.', array('@id' => $id)));
return $this->assertNoRaw('<div' . new Attribute(['data-contextual-id' => $id]) . '></div>', format_string('Contextual link placeholder with id @id does not exist.', ['@id' => $id]));
}
/**
@ -178,11 +178,11 @@ class ContextualDynamicContextTest extends WebTestBase {
* The response body.
*/
protected function renderContextualLinks($ids, $current_path) {
$post = array();
$post = [];
for ($i = 0; $i < count($ids); $i++) {
$post['ids[' . $i . ']'] = $ids[$i];
}
return $this->drupalPostWithFormat('contextual/render', 'json', $post, array('query' => array('destination' => $current_path)));
return $this->drupalPostWithFormat('contextual/render', 'json', $post, ['query' => ['destination' => $current_path]]);
}
}