Update to Drupal 8.0.0 beta 14. For more information, see https://drupal.org/node/2544542

This commit is contained in:
Pantheon Automation 2015-08-27 12:03:05 -07:00 committed by Greg Anderson
parent 3b2511d96d
commit 81ccda77eb
2155 changed files with 54307 additions and 46870 deletions

View file

@ -7,7 +7,7 @@
namespace Drupal\Core\Menu;
use Drupal\Core\Plugin\PluginBase;
use Drupal\Component\Plugin\PluginBase;
use Symfony\Component\HttpFoundation\Request;
/**
@ -17,21 +17,10 @@ class ContextualLinkDefault extends PluginBase implements ContextualLinkInterfac
/**
* {@inheritdoc}
*
* @todo: It might be helpful at some point to move this getTitle logic into
* a trait.
*/
public function getTitle(Request $request = NULL) {
$options = array();
if (!empty($this->pluginDefinition['title_context'])) {
$options['context'] = $this->pluginDefinition['title_context'];
}
$args = array();
if (isset($this->pluginDefinition['title_arguments']) && $title_arguments = $this->pluginDefinition['title_arguments']) {
$args = (array) $title_arguments;
}
return $this->t($this->pluginDefinition['title'], $args, $options);
// The title from YAML file discovery may be a TranslationWrapper object.
return (string) $this->pluginDefinition['title'];
}
/**

View file

@ -118,8 +118,9 @@ class ContextualLinkManager extends DefaultPluginManager implements ContextualLi
*/
protected function getDiscovery() {
if (!isset($this->discovery)) {
$this->discovery = new YamlDiscovery('links.contextual', $this->moduleHandler->getModuleDirectories());
$this->discovery = new ContainerDerivativeDiscoveryDecorator($this->discovery);
$yaml_discovery = new YamlDiscovery('links.contextual', $this->moduleHandler->getModuleDirectories());
$yaml_discovery->addTranslatableProperty('title', 'title_context');
$this->discovery = new ContainerDerivativeDiscoveryDecorator($yaml_discovery);
}
return $this->discovery;
}

View file

@ -8,7 +8,6 @@
namespace Drupal\Core\Menu;
use Drupal\Component\Plugin\Exception\PluginException;
use Drupal\Component\Utility\SafeMarkup;
/**
* A menu link plugin for wrapping another menu link, in sensitive situations.
@ -80,7 +79,7 @@ class InaccessibleMenuLink extends MenuLinkBase {
* {@inheritdoc}
*/
public function updateLink(array $new_definition_values, $persist) {
throw new PluginException(SafeMarkup::format('Inaccessible menu link plugins do not support updating'));
throw new PluginException('Inaccessible menu link plugins do not support updating');
}
}

View file

@ -7,8 +7,9 @@
namespace Drupal\Core\Menu;
use Drupal\Component\Plugin\PluginBase;
use Drupal\Core\DependencyInjection\DependencySerializationTrait;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\Core\Plugin\PluginBase;
use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\Core\Routing\RouteProviderInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
@ -19,6 +20,8 @@ use Symfony\Component\HttpFoundation\Request;
*/
class LocalActionDefault extends PluginBase implements LocalActionInterface, ContainerFactoryPluginInterface {
use DependencySerializationTrait;
/**
* The route provider to load routes by name.
*
@ -68,15 +71,8 @@ class LocalActionDefault extends PluginBase implements LocalActionInterface, Con
*/
public function getTitle(Request $request = NULL) {
// Subclasses may pull in the request or specific attributes as parameters.
$options = array();
if (!empty($this->pluginDefinition['title_context'])) {
$options['context'] = $this->pluginDefinition['title_context'];
}
$args = array();
if (isset($this->pluginDefinition['title_arguments']) && $title_arguments = $this->pluginDefinition['title_arguments']) {
$args = (array) $title_arguments;
}
return $this->t($this->pluginDefinition['title'], $args, $options);
// The title from YAML file discovery may be a TranslationWrapper object.
return (string) $this->pluginDefinition['title'];
}
/**

View file

@ -142,8 +142,9 @@ class LocalActionManager extends DefaultPluginManager implements LocalActionMana
*/
protected function getDiscovery() {
if (!isset($this->discovery)) {
$this->discovery = new YamlDiscovery('links.action', $this->moduleHandler->getModuleDirectories());
$this->discovery = new ContainerDerivativeDiscoveryDecorator($this->discovery);
$yaml_discovery = new YamlDiscovery('links.action', $this->moduleHandler->getModuleDirectories());
$yaml_discovery->addTranslatableProperty('title', 'title_context');
$this->discovery = new ContainerDerivativeDiscoveryDecorator($yaml_discovery);
}
return $this->discovery;
}

View file

@ -7,7 +7,8 @@
namespace Drupal\Core\Menu;
use Drupal\Core\Plugin\PluginBase;
use Drupal\Component\Plugin\PluginBase;
use Drupal\Core\DependencyInjection\DependencySerializationTrait;
use Drupal\Core\Routing\RouteMatchInterface;
use Symfony\Component\HttpFoundation\Request;
@ -16,6 +17,8 @@ use Symfony\Component\HttpFoundation\Request;
*/
class LocalTaskDefault extends PluginBase implements LocalTaskInterface {
use DependencySerializationTrait;
/**
* The route provider to load routes by name.
*
@ -75,16 +78,8 @@ class LocalTaskDefault extends PluginBase implements LocalTaskInterface {
* {@inheritdoc}
*/
public function getTitle(Request $request = NULL) {
// Subclasses may pull in the request or specific attributes as parameters.
$options = array();
if (!empty($this->pluginDefinition['title_context'])) {
$options['context'] = $this->pluginDefinition['title_context'];
}
$args = array();
if (isset($this->pluginDefinition['title_arguments']) && $title_arguments = $this->pluginDefinition['title_arguments']) {
$args = (array) $title_arguments;
}
return $this->t($this->pluginDefinition['title'], $args, $options);
// The title from YAML file discovery may be a TranslationWrapper object.
return (string) $this->pluginDefinition['title'];
}
/**

View file

@ -142,8 +142,9 @@ class LocalTaskManager extends DefaultPluginManager implements LocalTaskManagerI
*/
protected function getDiscovery() {
if (!isset($this->discovery)) {
$this->discovery = new YamlDiscovery('links.task', $this->moduleHandler->getModuleDirectories());
$this->discovery = new ContainerDerivativeDiscoveryDecorator($this->discovery);
$yaml_discovery = new YamlDiscovery('links.task', $this->moduleHandler->getModuleDirectories());
$yaml_discovery->addTranslatableProperty('title', 'title_context');
$this->discovery = new ContainerDerivativeDiscoveryDecorator($yaml_discovery);
}
return $this->discovery;
}

View file

@ -8,7 +8,6 @@
namespace Drupal\Core\Menu;
use Drupal\Component\Plugin\Exception\PluginException;
use Drupal\Component\Utility\SafeMarkup;
use Drupal\Core\Cache\Cache;
use Drupal\Core\Plugin\PluginBase;
use Drupal\Core\Url;
@ -170,7 +169,7 @@ abstract class MenuLinkBase extends PluginBase implements MenuLinkInterface {
* {@inheritdoc}
*/
public function deleteLink() {
throw new PluginException(SafeMarkup::format('Menu link plugin with ID @id does not support deletion', array('@id' => $this->getPluginId())));
throw new PluginException("Menu link plugin with ID '{$this->getPluginId()}' does not support deletion");
}
/**

View file

@ -67,26 +67,14 @@ class MenuLinkDefault extends MenuLinkBase implements ContainerFactoryPluginInte
* {@inheritdoc}
*/
public function getTitle() {
// Subclasses may pull in the request or specific attributes as parameters.
$options = array();
if (!empty($this->pluginDefinition['title_context'])) {
$options['context'] = $this->pluginDefinition['title_context'];
}
$args = array();
if (isset($this->pluginDefinition['title_arguments']) && $title_arguments = $this->pluginDefinition['title_arguments']) {
$args = (array) $title_arguments;
}
return $this->t($this->pluginDefinition['title'], $args, $options);
return (string) $this->pluginDefinition['title'];
}
/**
* {@inheritdoc}
*/
public function getDescription() {
if ($this->pluginDefinition['description']) {
return $this->t($this->pluginDefinition['description']);
}
return '';
return (string) $this->pluginDefinition['description'];
}
/**

View file

@ -10,7 +10,6 @@ namespace Drupal\Core\Menu;
use Drupal\Component\Plugin\Exception\PluginException;
use Drupal\Component\Plugin\Exception\PluginNotFoundException;
use Drupal\Component\Utility\NestedArray;
use Drupal\Component\Utility\SafeMarkup;
use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\Core\Plugin\Discovery\ContainerDerivativeDiscoveryDecorator;
use Drupal\Core\Plugin\Discovery\YamlDiscovery;
@ -41,15 +40,11 @@ class MenuLinkManager implements MenuLinkManagerInterface {
'route_parameters' => array(),
// The external URL if this link has one (required if route_name is empty).
'url' => '',
// The static title for the menu link. You can specify placeholders like on
// any translatable string and the values in title_arguments.
// The static title for the menu link. If this came from a YAML definition
// or other safe source this may be a TranslationWrapper object.
'title' => '',
// The values for the menu link placeholders.
'title_arguments' => array(),
// A context for the title string.
// @see \Drupal\Core\StringTranslation\TranslationInterface::translate()
'title_context' => '',
// The description.
// The description. If this came from a YAML definition or other safe source
// this may be be a TranslationWrapper object.
'description' => '',
// The plugin ID of the parent link (or NULL for a top-level link).
'parent' => '',
@ -148,8 +143,10 @@ class MenuLinkManager implements MenuLinkManagerInterface {
*/
protected function getDiscovery() {
if (!isset($this->discovery)) {
$this->discovery = new YamlDiscovery('links.menu', $this->moduleHandler->getModuleDirectories());
$this->discovery = new ContainerDerivativeDiscoveryDecorator($this->discovery);
$yaml_discovery = new YamlDiscovery('links.menu', $this->moduleHandler->getModuleDirectories());
$yaml_discovery->addTranslatableProperty('title', 'title_context');
$yaml_discovery->addTranslatableProperty('description', 'description_context');
$this->discovery = new ContainerDerivativeDiscoveryDecorator($yaml_discovery);
}
return $this->discovery;
}
@ -287,7 +284,7 @@ class MenuLinkManager implements MenuLinkManagerInterface {
}
}
else {
throw new PluginException(SafeMarkup::format('Menu link plugin with ID @id does not support deletion', array('@id' => $id)));
throw new PluginException("Menu link plugin with ID '$id' does not support deletion");
}
$this->treeStorage->delete($id);
}
@ -355,7 +352,7 @@ class MenuLinkManager implements MenuLinkManagerInterface {
*/
public function addDefinition($id, array $definition) {
if ($this->treeStorage->load($id) || $id === '') {
throw new PluginException(SafeMarkup::format('The ID @id already exists as a plugin definition or is not valid', array('@id' => $id)));
throw new PluginException("The ID $id already exists as a plugin definition or is not valid");
}
// Add defaults, so there is no requirement to specify everything.
$this->processDefinition($definition, $id);
@ -402,7 +399,7 @@ class MenuLinkManager implements MenuLinkManagerInterface {
$id = $instance->getPluginId();
if (!$instance->isResettable()) {
throw new PluginException(SafeMarkup::format('Menu link %id is not resettable', array('%id' => $id)));
throw new PluginException("Menu link $id is not resettable");
}
// Get the original data from disk, reset the override and re-save the menu
// tree for this link.

View file

@ -16,10 +16,6 @@ namespace Drupal\Core\Menu;
* - Which parent IDs should be used to restrict the tree. Only links with
* a parent in the list will be included.
* - Which menu links are omitted, depending on the minimum and maximum depth.
*
* @todo Add getter methods and make all properties protected and define an
* interface instead of using the concrete class to type hint.
* https://www.drupal.org/node/2302041
*/
class MenuTreeParameters {

View file

@ -8,7 +8,6 @@
namespace Drupal\Core\Menu;
use Drupal\Component\Plugin\Exception\PluginException;
use Drupal\Component\Utility\SafeMarkup;
use Drupal\Component\Utility\UrlHelper;
use Drupal\Core\Cache\Cache;
use Drupal\Core\Cache\CacheBackendInterface;
@ -95,8 +94,6 @@ class MenuTreeStorage implements MenuTreeStorageInterface {
'route_parameters',
'url',
'title',
'title_arguments',
'title_context',
'description',
'parent',
'weight',
@ -367,7 +364,9 @@ class MenuTreeStorage implements MenuTreeStorageInterface {
$fields['route_param_key'] = $fields['route_parameters'] ? UrlHelper::buildQuery($fields['route_parameters']) : '';
foreach ($this->serializedFields() as $name) {
$fields[$name] = serialize($fields[$name]);
if (isset($fields[$name])) {
$fields[$name] = serialize($fields[$name]);
}
}
$this->setParents($fields, $parent, $original);
@ -476,7 +475,7 @@ class MenuTreeStorage implements MenuTreeStorageInterface {
$limit = $this->maxDepth() - 1;
}
if ($parent['depth'] > $limit) {
throw new PluginException(SafeMarkup::format('The link with ID @id or its children exceeded the maximum depth of @depth', array('@id' => $fields['id'], '@depth' => $this->maxDepth())));
throw new PluginException("The link with ID {$fields['id']} or its children exceeded the maximum depth of {$this->maxDepth()}");
}
$fields['depth'] = $parent['depth'] + 1;
$i = 1;
@ -619,7 +618,9 @@ class MenuTreeStorage implements MenuTreeStorageInterface {
*/
protected function prepareLink(array $link, $intersect = FALSE) {
foreach ($this->serializedFields() as $name) {
$link[$name] = unserialize($link[$name]);
if (isset($link[$name])) {
$link[$name] = unserialize($link[$name]);
}
}
if ($intersect) {
$link = array_intersect_key($link, array_flip($this->definitionFields()));
@ -637,7 +638,7 @@ class MenuTreeStorage implements MenuTreeStorageInterface {
foreach ($properties as $name => $value) {
if (!in_array($name, $this->definitionFields(), TRUE)) {
$fields = implode(', ', $this->definitionFields());
throw new \InvalidArgumentException(SafeMarkup::format('An invalid property name, @name was specified. Allowed property names are: @fields.', array('@name' => $name, '@fields' => $fields)));
throw new \InvalidArgumentException("An invalid property name, $name was specified. Allowed property names are: $fields.");
}
$query->condition($name, $value);
}
@ -736,7 +737,9 @@ class MenuTreeStorage implements MenuTreeStorageInterface {
$loaded = $this->safeExecuteSelect($query)->fetchAllAssoc('id', \PDO::FETCH_ASSOC);
foreach ($loaded as &$link) {
foreach ($this->serializedFields() as $name) {
$link[$name] = unserialize($link[$name]);
if (isset($link[$name])) {
$link[$name] = unserialize($link[$name]);
}
}
}
return $loaded;
@ -927,15 +930,19 @@ class MenuTreeStorage implements MenuTreeStorageInterface {
if (!empty($parameters->conditions)) {
// Only allow conditions that are testing definition fields.
$parameters->conditions = array_intersect_key($parameters->conditions, array_flip($this->definitionFields()));
$serialized_fields = $this->serializedFields();
foreach ($parameters->conditions as $column => $value) {
if (!is_array($value)) {
$query->condition($column, $value);
}
else {
if (is_array($value)) {
$operator = $value[1];
$value = $value[0];
$query->condition($column, $value, $operator);
}
else {
$operator = '=';
}
if (in_array($column, $serialized_fields)) {
$value = serialize($value);
}
$query->condition($column, $value, $operator);
}
}
@ -1242,30 +1249,18 @@ class MenuTreeStorage implements MenuTreeStorageInterface {
'default' => '',
),
'title' => array(
'description' => 'The text displayed for the link.',
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
),
'title_arguments' => array(
'description' => 'A serialized array of arguments to be passed to t() (if this plugin uses it).',
'description' => 'The serialized title for the link. May be a TranslationWrapper.',
'type' => 'blob',
'size' => 'big',
'not null' => FALSE,
'serialize' => TRUE,
),
'title_context' => array(
'description' => 'The translation context for the link title.',
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
),
'description' => array(
'description' => 'The description of this link - used for admin pages and title attribute.',
'type' => 'text',
'description' => 'The serialized description of this link - used for admin pages and title attribute. May be a TranslationWrapper.',
'type' => 'blob',
'size' => 'big',
'not null' => FALSE,
'serialize' => TRUE,
),
'class' => array(
'description' => 'The class for this link plugin.',

View file

@ -334,8 +334,12 @@
*
* The value corresponding to each machine name key is an associative array
* that may contain the following key-value pairs:
* - title: (required) The untranslated title of the menu link.
* - description: The untranslated description of the link.
* - title: (required) The title of the menu link. If this should be
* translated, create a \Drupal\Core\StringTranslation\TranslationWrapper
* object.
* - description: The description of the link. If this should be
* translated, create a \Drupal\Core\StringTranslation\TranslationWrapper
* object.
* - route_name: (optional) The route name to be used to build the path.
* Either the route_name or url element must be provided.
* - route_parameters: (optional) The route parameters to build the path.
@ -360,7 +364,16 @@
function hook_menu_links_discovered_alter(&$links) {
// Change the weight and title of the user.logout link.
$links['user.logout']['weight'] = -10;
$links['user.logout']['title'] = 'Logout';
$links['user.logout']['title'] = new \Drupal\Core\StringTranslation\TranslationWrapper('Logout');
// Conditionally add an additional link with a title that's not translated.
if (\Drupal::moduleHandler()->moduleExists('search')) {
$links['menu.api.search'] = array(
'title' => \Drupal::config('system.site')->get('name'),
'route_name' => 'menu.api.search',
'description' => new \Drupal\Core\StringTranslation\TranslationWrapper('View popular search phrases for this site.'),
'parent' => 'system.admin_reports',
);
}
}
/**