Update to drupal-org-drupal 8.0.0-rc2. For more information, see https://www.drupal.org/node/2598668
This commit is contained in:
parent
f32e58e4b1
commit
8e18df8c36
3062 changed files with 15044 additions and 172506 deletions
143
core/lib/Drupal/Core/Entity/Controller/EntityController.php
Normal file
143
core/lib/Drupal/Core/Entity/Controller/EntityController.php
Normal file
|
@ -0,0 +1,143 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\Core\Entity\Controller\EntityController.
|
||||
*/
|
||||
|
||||
namespace Drupal\Core\Entity\Controller;
|
||||
|
||||
use Drupal\Core\Entity\EntityManagerInterface;
|
||||
use Drupal\Core\Routing\RouteMatchInterface;
|
||||
use Drupal\Core\Entity\EntityInterface;
|
||||
use Drupal\Core\DependencyInjection\ContainerInjectionInterface;
|
||||
use Drupal\Core\StringTranslation\StringTranslationTrait;
|
||||
use Drupal\Core\StringTranslation\TranslationInterface;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
|
||||
/**
|
||||
* Provides generic entity title callbacks for use in routing.
|
||||
*
|
||||
* It provides:
|
||||
* - A view title callback.
|
||||
* - An edit title callback.
|
||||
* - A delete title callback.
|
||||
*/
|
||||
class EntityController implements ContainerInjectionInterface {
|
||||
|
||||
use StringTranslationTrait;
|
||||
|
||||
/**
|
||||
* The entity manager.
|
||||
*
|
||||
* @var \Drupal\Core\Entity\EntityManagerInterface
|
||||
*/
|
||||
protected $entityManager;
|
||||
|
||||
/**
|
||||
* Constructs a new EntityController.
|
||||
*
|
||||
* @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager
|
||||
* The entity manager.
|
||||
* @param \Drupal\Core\StringTranslation\TranslationInterface $string_translation
|
||||
* The string translation.
|
||||
*/
|
||||
public function __construct(EntityManagerInterface $entity_manager, TranslationInterface $string_translation) {
|
||||
$this->entityManager = $entity_manager;
|
||||
$this->stringTranslation = $string_translation;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function create(ContainerInterface $container) {
|
||||
return new static(
|
||||
$container->get('entity.manager'),
|
||||
$container->get('string_translation')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides a generic title callback for a single entity.
|
||||
*
|
||||
* @param \Drupal\Core\Routing\RouteMatchInterface $route_match
|
||||
* The route match.
|
||||
* @param \Drupal\Core\Entity\EntityInterface $_entity
|
||||
* (optional) An entity, passed in directly from the request attributes.
|
||||
*
|
||||
* @return string
|
||||
* The title for the entity view page.
|
||||
*/
|
||||
public function title(RouteMatchInterface $route_match, EntityInterface $_entity = NULL) {
|
||||
if ($entity = $this->doGetEntity($route_match, $_entity)) {
|
||||
return $entity->label();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides a generic edit title callback.
|
||||
*
|
||||
* @param \Drupal\Core\Routing\RouteMatchInterface $route_match
|
||||
* The route match.
|
||||
* @param \Drupal\Core\Entity\EntityInterface $_entity
|
||||
* (optional) An entity, passed in directly from the request attributes.
|
||||
*
|
||||
* @return string
|
||||
* The title for the entity edit page.
|
||||
*/
|
||||
public function editTitle(RouteMatchInterface $route_match, EntityInterface $_entity = NULL) {
|
||||
if ($entity = $this->doGetEntity($route_match, $_entity)) {
|
||||
return $this->t('Edit %label', ['%label' => $entity->label()]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides a generic delete title callback.
|
||||
*
|
||||
* @param \Drupal\Core\Routing\RouteMatchInterface $route_match
|
||||
* The route match.
|
||||
* @param \Drupal\Core\Entity\EntityInterface $_entity
|
||||
* (optional) An entity, passed in directly from the request attributes, and
|
||||
* set in \Drupal\Core\Entity\Enhancer\EntityRouteEnhancer.
|
||||
*
|
||||
* @return string
|
||||
* The title for the delete entity page.
|
||||
*/
|
||||
public function deleteTitle(RouteMatchInterface $route_match, EntityInterface $_entity = NULL) {
|
||||
if ($entity = $this->doGetEntity($route_match, $_entity)) {
|
||||
return $this->t('Delete %label', ['%label' => $entity->label()]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines the entity.
|
||||
*
|
||||
* @param \Drupal\Core\Routing\RouteMatchInterface $route_match
|
||||
* The route match.
|
||||
* @param \Drupal\Core\Entity\EntityInterface $_entity
|
||||
* (optional) The entity, set in
|
||||
* \Drupal\Core\Entity\Enhancer\EntityRouteEnhancer.
|
||||
*
|
||||
* @return \Drupal\Core\Entity\EntityInterface|NULL
|
||||
* The entity, if it is passed in directly or if the first parameter of the
|
||||
* active route is an entity; otherwise, NULL.
|
||||
*/
|
||||
protected function doGetEntity(RouteMatchInterface $route_match, EntityInterface $_entity = NULL) {
|
||||
if ($_entity) {
|
||||
$entity = $_entity;
|
||||
}
|
||||
else {
|
||||
// Let's look up in the route object for the name of upcasted values.
|
||||
foreach ($route_match->getParameters() as $parameter) {
|
||||
if ($parameter instanceof EntityInterface) {
|
||||
$entity = $parameter;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($entity) {
|
||||
return $this->entityManager->getTranslationFromContext($entity);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -8,7 +8,6 @@
|
|||
namespace Drupal\Core\Entity\Controller;
|
||||
|
||||
use Drupal\Core\Controller\ControllerBase;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
|
||||
/**
|
||||
* Defines a generic controller to list entities.
|
||||
|
|
|
@ -10,7 +10,6 @@ namespace Drupal\Core\Entity;
|
|||
use Drupal\Core\Cache\Cache;
|
||||
use Drupal\Core\Cache\RefinableCacheableDependencyTrait;
|
||||
use Drupal\Core\DependencyInjection\DependencySerializationTrait;
|
||||
use Drupal\Component\Utility\SafeMarkup;
|
||||
use Drupal\Component\Utility\Unicode;
|
||||
use Drupal\Core\Config\Entity\Exception\ConfigEntityIdLengthException;
|
||||
use Drupal\Core\Entity\Exception\UndefinedLinkTemplateException;
|
||||
|
|
|
@ -10,7 +10,6 @@ namespace Drupal\Core\Entity;
|
|||
use Drupal\Core\Field\FieldItemListInterface;
|
||||
use Drupal\Core\Extension\ModuleHandlerInterface;
|
||||
use Drupal\Core\Field\FieldDefinitionInterface;
|
||||
use Drupal\Core\Language\LanguageInterface;
|
||||
use Drupal\Core\Session\AccountInterface;
|
||||
|
||||
/**
|
||||
|
|
|
@ -10,7 +10,6 @@ namespace Drupal\Core\Entity;
|
|||
use Drupal\Core\Form\ConfirmFormHelper;
|
||||
use Drupal\Core\Form\ConfirmFormInterface;
|
||||
use Drupal\Core\Form\FormStateInterface;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
|
||||
/**
|
||||
* Provides a generic base class for an entity-based confirmation form.
|
||||
|
|
|
@ -7,7 +7,6 @@
|
|||
|
||||
namespace Drupal\Core\Entity;
|
||||
|
||||
use Drupal\Core\Extension\ModuleHandlerInterface;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
|
||||
/**
|
||||
|
|
|
@ -24,7 +24,6 @@ use Drupal\Core\Field\FieldStorageDefinitionEvents;
|
|||
use Drupal\Core\Field\FieldStorageDefinitionInterface;
|
||||
use Drupal\Core\Field\FieldStorageDefinitionListenerInterface;
|
||||
use Drupal\Core\KeyValueStore\KeyValueFactoryInterface;
|
||||
use Drupal\Core\KeyValueStore\KeyValueStoreInterface;
|
||||
use Drupal\Core\Language\LanguageInterface;
|
||||
use Drupal\Core\Language\LanguageManagerInterface;
|
||||
use Drupal\Core\Plugin\DefaultPluginManager;
|
||||
|
@ -1133,7 +1132,7 @@ class EntityManager extends DefaultPluginManager implements EntityManagerInterfa
|
|||
}
|
||||
|
||||
/**
|
||||
* Returns an array of display mode options by bundle.
|
||||
* Returns an array of enabled display mode options by bundle.
|
||||
*
|
||||
* @param $display_type
|
||||
* The display type to be retrieved. It can be "view_mode" or "form_mode".
|
||||
|
|
|
@ -450,7 +450,7 @@ interface EntityManagerInterface extends PluginManagerInterface, EntityTypeListe
|
|||
public function getFormModeOptions($entity_type_id);
|
||||
|
||||
/**
|
||||
* Returns an array of view mode options by bundle.
|
||||
* Returns an array of enabled view mode options by bundle.
|
||||
*
|
||||
* @param string $entity_type_id
|
||||
* The entity type whose view mode options should be returned.
|
||||
|
@ -463,7 +463,7 @@ interface EntityManagerInterface extends PluginManagerInterface, EntityTypeListe
|
|||
public function getViewModeOptionsByBundle($entity_type_id, $bundle);
|
||||
|
||||
/**
|
||||
* Returns an array of form mode options by bundle.
|
||||
* Returns an array of enabled form mode options by bundle.
|
||||
*
|
||||
* @param string $entity_type_id
|
||||
* The entity type whose form mode options should be returned.
|
||||
|
|
|
@ -87,7 +87,7 @@ abstract class ConditionFundamentals {
|
|||
*/
|
||||
public function __clone() {
|
||||
foreach ($this->conditions as $key => $condition) {
|
||||
if ($condition['field'] instanceOf ConditionInterface) {
|
||||
if ($condition['field'] instanceof ConditionInterface) {
|
||||
$this->conditions[$key]['field'] = clone($condition['field']);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -37,7 +37,7 @@ class Condition extends ConditionBase {
|
|||
$sql_query = $conditionContainer instanceof SelectInterface ? $conditionContainer : $conditionContainer->sqlQuery;
|
||||
$tables = $this->query->getTables($sql_query);
|
||||
foreach ($this->conditions as $condition) {
|
||||
if ($condition['field'] instanceOf ConditionInterface) {
|
||||
if ($condition['field'] instanceof ConditionInterface) {
|
||||
$sql_condition = new SqlCondition($condition['field']->getConjunction());
|
||||
// Add the SQL query to the object before calling this method again.
|
||||
$sql_condition->sqlQuery = $sql_query;
|
||||
|
|
|
@ -30,7 +30,7 @@ class ConditionAggregate extends ConditionAggregateBase {
|
|||
$sql_query = ($conditionContainer instanceof SelectInterface) ? $conditionContainer : $conditionContainer->sqlQuery;
|
||||
$tables = new Tables($sql_query);
|
||||
foreach ($this->conditions as $condition) {
|
||||
if ($condition['field'] instanceOf ConditionAggregateInterface) {
|
||||
if ($condition['field'] instanceof ConditionAggregateInterface) {
|
||||
$sql_condition = new SqlCondition($condition['field']->getConjunction());
|
||||
// Add the SQL query to the object before calling this method again.
|
||||
$sql_condition->sqlQuery = $sql_query;
|
||||
|
|
|
@ -8,7 +8,6 @@
|
|||
namespace Drupal\Core\Entity\Query\Sql;
|
||||
|
||||
use Drupal\Core\Database\Connection;
|
||||
use Drupal\Core\Entity\EntityManagerInterface;
|
||||
use Drupal\Core\Entity\EntityTypeInterface;
|
||||
use Drupal\Core\Entity\Query\QueryBase;
|
||||
use Drupal\Core\Entity\Query\QueryFactoryInterface;
|
||||
|
|
|
@ -0,0 +1,44 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\Core\Entity\Routing\AdminHtmlRouteProvider.
|
||||
*/
|
||||
|
||||
namespace Drupal\Core\Entity\Routing;
|
||||
|
||||
use Drupal\Core\Entity\EntityTypeInterface;
|
||||
|
||||
/**
|
||||
* Provides HTML routes for entities with administrative edit/delete pages.
|
||||
*
|
||||
* Use this class if the edit and delete form routes should use the
|
||||
* administrative theme.
|
||||
*
|
||||
* @see \Drupal\Core\Entity\Routing\DefaultHtmlRouteProvider.
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
class AdminHtmlRouteProvider extends DefaultHtmlRouteProvider {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function getEditFormRoute(EntityTypeInterface $entity_type) {
|
||||
if ($route = parent::getEditFormRoute($entity_type)) {
|
||||
$route->setOption('_admin_route', TRUE);
|
||||
return $route;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function getDeleteFormRoute(EntityTypeInterface $entity_type) {
|
||||
if ($route = parent::getDeleteFormRoute($entity_type)) {
|
||||
$route->setOption('_admin_route', TRUE);
|
||||
return $route;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
135
core/lib/Drupal/Core/Entity/Routing/DefaultHtmlRouteProvider.php
Normal file
135
core/lib/Drupal/Core/Entity/Routing/DefaultHtmlRouteProvider.php
Normal file
|
@ -0,0 +1,135 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\Core\Entity\Routing\DefaultHtmlRouteProvider.
|
||||
*/
|
||||
|
||||
namespace Drupal\Core\Entity\Routing;
|
||||
|
||||
use Drupal\Core\Entity\EntityTypeInterface;
|
||||
use Symfony\Component\Routing\Route;
|
||||
use Symfony\Component\Routing\RouteCollection;
|
||||
|
||||
/**
|
||||
* Provides HTML routes for entities.
|
||||
*
|
||||
* This class provides the following routes for entities, with title and access
|
||||
* callbacks:
|
||||
* - canonical
|
||||
* - edit-form
|
||||
* - delete-form
|
||||
*
|
||||
* @see \Drupal\Core\Entity\Routing\AdminHtmlRouteProvider.
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
class DefaultHtmlRouteProvider implements EntityRouteProviderInterface {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getRoutes(EntityTypeInterface $entity_type) {
|
||||
$collection = new RouteCollection();
|
||||
|
||||
$entity_type_id = $entity_type->id();
|
||||
|
||||
if ($edit_route = $this->getEditFormRoute($entity_type)) {
|
||||
$collection->add("entity.{$entity_type_id}.edit_form", $edit_route);
|
||||
}
|
||||
|
||||
if ($canonical_route = $this->getCanonicalRoute($entity_type)) {
|
||||
$collection->add("entity.{$entity_type_id}.canonical", $canonical_route);
|
||||
}
|
||||
|
||||
if ($delete_route = $this->getDeleteFormRoute($entity_type)) {
|
||||
$collection->add("entity.{$entity_type_id}.delete_form", $delete_route);
|
||||
}
|
||||
|
||||
return $collection;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the canonical route.
|
||||
*
|
||||
* @param \Drupal\Core\Entity\EntityTypeInterface $entity_type
|
||||
* The entity type.
|
||||
*
|
||||
* @return \Symfony\Component\Routing\Route|null
|
||||
* The generated route, if available.
|
||||
*/
|
||||
protected function getCanonicalRoute(EntityTypeInterface $entity_type) {
|
||||
if ($entity_type->hasLinkTemplate('canonical') && $entity_type->hasViewBuilderClass()) {
|
||||
$entity_type_id = $entity_type->id();
|
||||
$route = new Route($entity_type->getLinkTemplate('canonical'));
|
||||
$route
|
||||
->addDefaults([
|
||||
'_entity_view' => "{$entity_type_id}.full",
|
||||
'_title_callback' => '\Drupal\Core\Entity\Controller\EntityController::title',
|
||||
])
|
||||
->setRequirement('_entity_access', "{$entity_type_id}.view")
|
||||
->setOption('parameters', [
|
||||
$entity_type_id => ['type' => 'entity:' . $entity_type_id],
|
||||
]);
|
||||
return $route;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the edit-form route.
|
||||
*
|
||||
* @param \Drupal\Core\Entity\EntityTypeInterface $entity_type
|
||||
* The entity type.
|
||||
*
|
||||
* @return \Symfony\Component\Routing\Route|null
|
||||
* The generated route, if available.
|
||||
*/
|
||||
protected function getEditFormRoute(EntityTypeInterface $entity_type) {
|
||||
if ($entity_type->hasLinkTemplate('edit-form')) {
|
||||
$entity_type_id = $entity_type->id();
|
||||
$route = new Route($entity_type->getLinkTemplate('edit-form'));
|
||||
// Use the edit form handler, if available, otherwise default.
|
||||
$operation = 'default';
|
||||
if ($entity_type->getFormClass('edit')) {
|
||||
$operation = 'edit';
|
||||
}
|
||||
$route
|
||||
->setDefaults([
|
||||
'_entity_form' => "{$entity_type_id}.{$operation}",
|
||||
'_title_callback' => '\Drupal\Core\Entity\Controller\EntityController::editTitle'
|
||||
])
|
||||
->setRequirement('_entity_access', "{$entity_type_id}.update")
|
||||
->setOption('parameters', [
|
||||
$entity_type_id => ['type' => 'entity:' . $entity_type_id],
|
||||
]);
|
||||
return $route;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the delete-form route.
|
||||
*
|
||||
* @param \Drupal\Core\Entity\EntityTypeInterface $entity_type
|
||||
* The entity type.
|
||||
*
|
||||
* @return \Symfony\Component\Routing\Route|null
|
||||
* The generated route, if available.
|
||||
*/
|
||||
protected function getDeleteFormRoute(EntityTypeInterface $entity_type) {
|
||||
if ($entity_type->hasLinkTemplate('delete-form')) {
|
||||
$entity_type_id = $entity_type->id();
|
||||
$route = new Route($entity_type->getLinkTemplate('delete-form'));
|
||||
$route
|
||||
->addDefaults([
|
||||
'_entity_form' => "{$entity_type_id}.delete",
|
||||
'_title_callback' => '\Drupal\Core\Entity\Controller\EntityController::deleteTitle',
|
||||
])
|
||||
->setRequirement('_entity_access', "{$entity_type_id}.delete")
|
||||
->setOption('parameters', [
|
||||
$entity_type_id => ['type' => 'entity:' . $entity_type_id],
|
||||
]);
|
||||
return $route;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -324,7 +324,9 @@ use Drupal\node\Entity\NodeType;
|
|||
* also need to add a corresponding route to your module's routing.yml file;
|
||||
* see the entity.node.canonical route in node.routing.yml for an example, and see
|
||||
* @ref sec_routes below for some notes.
|
||||
* - Define routes and links for the various URLs associated with the entity.
|
||||
* - Optionally, instead of defining routes, routes can be auto generated by
|
||||
* providing a route handler. See @ref sec_routes. Otherwise, define routes
|
||||
* and links for the various URLs associated with the entity.
|
||||
* These go into the 'links' annotation, with the link type as the key, and
|
||||
* the path of this link template as the value. The corresponding route
|
||||
* requires the following route name:
|
||||
|
@ -358,8 +360,10 @@ use Drupal\node\Entity\NodeType;
|
|||
*
|
||||
* @section sec_routes Entity routes
|
||||
* Entity routes, like other routes, are defined in *.routing.yml files; see
|
||||
* the @link menu Menu and routing @endlink topic for more information. Here
|
||||
* is a typical entry, for the block configure form:
|
||||
* the @link routing Routing API @endlink topic for more information. Entities
|
||||
* may alternatively use an auto route provider class; there is an example of
|
||||
* this at the end of this section. If providing routes directly, here is a
|
||||
* typical entry, for the block configure form:
|
||||
* @code
|
||||
* entity.block.edit_form:
|
||||
* path: '/admin/structure/block/manage/{block}'
|
||||
|
@ -386,6 +390,19 @@ use Drupal\node\Entity\NodeType;
|
|||
* "form" = {
|
||||
* "default" = "Drupal\block\BlockForm",
|
||||
* @endcode
|
||||
* - Instead of putting the routes for your entity in a *.routing.yml file, you
|
||||
* can instead use a route provider class.
|
||||
* \Drupal\Core\Entity\Routing\DefaultHtmlRouteProvider provides canonical,
|
||||
* edit-form, and delete-form routes;
|
||||
* \Drupal\Core\Entity\Routing\AdminHtmlRouteProvider provides the same
|
||||
* routes, set up to use the administrative theme for edit and delete pages.
|
||||
* You can also create your own class. To use a route provider class, add
|
||||
* lines like the following to your entity annotation:
|
||||
* @code
|
||||
* handlers = {
|
||||
* "route_provider" = {
|
||||
* "html" = "Drupal\Core\Entity\Routing\DefaultHtmlRouteProvider",
|
||||
* @endcode
|
||||
*
|
||||
* @section bundle Defining a content entity bundle
|
||||
* For entity types that use bundles, such as Node (bundles are content types)
|
||||
|
|
Reference in a new issue