diff --git a/.travis.yml b/.travis.yml index 477301aacf75b10f1dc73ea7c046709fb68114dc..052224c7841e1445727f272122b7c73a344bc743 100644 --- a/.travis.yml +++ b/.travis.yml @@ -38,8 +38,10 @@ before_script: # Export database variable for kernel tests. - export SIMPLETEST_DB=mysql://root:@127.0.0.1/entity # Download Drupal 8 core. - - travis_retry git clone --branch 8.0.x --depth 1 http://git.drupal.org/project/drupal.git + - travis_retry git clone --branch 8.1.x --depth 1 http://git.drupal.org/project/drupal.git - cd drupal + - composer self-update + - composer install -n # Reference entity in build site. - ln -s $TESTDIR modules/entity diff --git a/composer.json b/composer.json index f340fe9bc3dbef34dc699c212a97919d3803bb74..b41c15ad71d28b224183e6e06f59cf67127088a4 100644 --- a/composer.json +++ b/composer.json @@ -3,5 +3,8 @@ "type": "drupal-module", "description": "Provides expanded entity APIs, which will be moved to Drupal core one day.", "homepage": "http://drupal.org/project/entity", - "license": "GPL-2.0+" + "license": "GPL-2.0+", + "require": { + "drupal/core": "~8.1" + } } diff --git a/entity.info.yml b/entity.info.yml index cf0997138b13ada1ae1757745303d83212287001..0b032e65dcede43c83c258dfb8d41bacee4f7aaa 100644 --- a/entity.info.yml +++ b/entity.info.yml @@ -2,3 +2,5 @@ name: Entity description: Provides expanded entity APIs, which will be moved to Drupal core one day. type: module core: 8.x +dependencies: + - system (>=8.1.0) diff --git a/entity.module b/entity.module index f1845403d133d6e80fa2581a5d4153f70063eb4b..8f330b28edeb36b49aaa5084a66ed66527ad9513 100644 --- a/entity.module +++ b/entity.module @@ -4,44 +4,3 @@ * @file * Provides expanded entity APIs. */ - -use Drupal\Core\Url; - -/** - * Implements hook_theme(). - */ -function entity_theme() { - return [ - 'entity_add_list' => [ - 'variables' => [ - 'bundles' => [], - 'bundle_type' => NULL, - ], - 'template' => 'entity-add-list', - ], - ]; -} - -/** - * Prepares variables for the list of available bundles. - * - * Default template: entity-add-list.html.twig. - * - * @param array $variables - * An associative array containing: - * - bundle_type: The entity type of the bundles. - * - bundles: An array of bundles with the label, description, add_link keys. - */ -function template_preprocess_entity_add_list(&$variables) { - $bundle_type = \Drupal::entityTypeManager()->getDefinition($variables['bundle_type']); - $variables += [ - 'create_bundle_url' => Url::fromRoute('entity.' . $bundle_type->id() . '.add_form')->toString(), - 'bundle_type_label' => $bundle_type->getLowercaseLabel(), - ]; - - foreach ($variables['bundles'] as $bundle_name => $bundle_info) { - $variables['bundles'][$bundle_name]['description'] = [ - '#markup' => $bundle_info['description'], - ]; - } -} diff --git a/entity.services.yml b/entity.services.yml index 3abb91e40048fddbdf3521862065d017feb4732a..0cb872c91e4417899342cd0580a2c97f882e0764 100644 --- a/entity.services.yml +++ b/entity.services.yml @@ -1,15 +1,4 @@ services: - param_converter.entity_revision: - class: \Drupal\entity\ParamConverter\EntityRevisionParamConverter - arguments: ['@entity_type.manager'] - tags: - - { name: paramconverter } - - route_enhancer.entity_revision: - class: Drupal\entity\RouteEnhancer\EntityRevisionRouteEnhancer - tags: - - { name: route_enhancer, priority: 20 } - access_checker.entity_revision: class: \Drupal\entity\Access\EntityRevisionRouteAccessChecker arguments: ['@entity_type.manager'] diff --git a/src/Controller/EntityCreateController.php b/src/Controller/EntityCreateController.php deleted file mode 100644 index f6b6896f83cb01e1542ee8fc67fa7d6d4997346e..0000000000000000000000000000000000000000 --- a/src/Controller/EntityCreateController.php +++ /dev/null @@ -1,221 +0,0 @@ -<?php - -/** - * @file - * Contains \Drupal\entity\Controller\EntityCreateController. - */ - -namespace Drupal\entity\Controller; - -use Drupal\Core\Controller\ControllerBase; -use Drupal\Core\Entity\EntityTypeBundleInfoInterface; -use Drupal\Core\Render\RendererInterface; -use Drupal\Core\Routing\RouteMatchInterface; -use Drupal\Core\Link; -use Symfony\Component\DependencyInjection\ContainerInterface; -use Symfony\Component\HttpFoundation\Request; -use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; - -/** - * A generic controller for creating entities. - */ -class EntityCreateController extends ControllerBase { - - /** - * The entity type bundle info. - * - * @var \Drupal\Core\Entity\EntityTypeBundleInfoInterface - */ - protected $entityTypeBundleInfo; - - /** - * The renderer service. - * - * @var \Drupal\Core\Render\RendererInterface - */ - protected $renderer; - - /** - * Constructs a new EntityCreateController object. - * - * @param \Drupal\Core\Entity\EntityTypeBundleInfoInterface $entity_type_bundle_info - * The entity type bundle info. - * @param \Drupal\Core\Render\RendererInterface $renderer - * The renderer. - */ - public function __construct(EntityTypeBundleInfoInterface $entity_type_bundle_info, RendererInterface $renderer) { - $this->entityTypeBundleInfo = $entity_type_bundle_info; - $this->renderer = $renderer; - } - - /** - * {@inheritdoc} - */ - public static function create(ContainerInterface $container) { - return new static( - $container->get('entity_type.bundle.info'), - $container->get('renderer') - ); - } - - /** - * Displays add links for the available bundles. - * - * Redirects to the add form if there's only one bundle available. - * - * @param string $entity_type_id - * The entity type ID. - * - * @return \Symfony\Component\HttpFoundation\RedirectResponse|array - * If there's only one available bundle, a redirect response. - * Otherwise, a render array with the add links for each bundle. - */ - public function addPage($entity_type_id) { - $entity_type = $this->entityTypeManager()->getDefinition($entity_type_id); - $bundle_type = $entity_type->getBundleEntityType(); - $bundle_key = $entity_type->getKey('bundle'); - $form_route_name = 'entity.' . $entity_type_id . '.add_form'; - $build = [ - '#theme' => 'entity_add_list', - '#cache' => [ - 'tags' => $entity_type->getListCacheTags(), - ], - '#bundle_type' => $bundle_type, - ]; - $bundles = $this->entityTypeBundleInfo->getBundleInfo($entity_type_id); - // Filter out the bundles the user doesn't have access to. - $access_control_handler = $this->entityTypeManager()->getAccessControlHandler($bundle_type); - foreach ($bundles as $bundle_name => $bundle_info) { - $access = $access_control_handler->createAccess($bundle_name, NULL, [], TRUE); - if (!$access->isAllowed()) { - unset($bundles[$bundle_name]); - } - $this->renderer->addCacheableDependency($build, $access); - } - // Redirect if there's only one bundle available. - if (count($bundles) == 1) { - $bundle_names = array_keys($bundles); - $bundle_name = reset($bundle_names); - return $this->redirect($form_route_name, [$bundle_key => $bundle_name]); - } - // Prepare the #bundles array for the template. - $bundles = $this->loadBundleDescriptions($bundles, $bundle_type); - foreach ($bundles as $bundle_name => $bundle_info) { - $build['#bundles'][$bundle_name] = [ - 'label' => $bundle_info['label'], - 'description' => $bundle_info['description'], - 'add_link' => Link::createFromRoute($bundle_info['label'], $form_route_name, [$bundle_key => $bundle_name]), - ]; - } - - return $build; - } - - /** - * The title callback for the add page. - * - * @param string $entity_type_id - * The entity type ID. - * - * @return string - * The page title. - */ - public function addPageTitle($entity_type_id) { - $entity_type = $this->entityTypeManager()->getDefinition($entity_type_id); - return $this->t('Add @entity-type', ['@entity-type' => $entity_type->getLowercaseLabel()]); - } - - /** - * Provides the add form for an entity. - * - * @param string $entity_type_id - * The entity type ID. - * @param \Drupal\Core\Routing\RouteMatchInterface $route_match - * The route match. - * - * @return array - * The add form. - * - * @throws \Symfony\Component\HttpKernel\Exception\NotFoundHttpException - * Thrown when the bundle parameter is invalid. - */ - public function addForm($entity_type_id, RouteMatchInterface $route_match) { - $entity_type = $this->entityTypeManager()->getDefinition($entity_type_id); - $values = []; - // Entities of this type have bundles, one was provided in the url. - if ($bundle_key = $entity_type->getKey('bundle')) { - $bundle_name = $route_match->getRawParameter($bundle_key); - $bundles = $this->entityTypeBundleInfo->getBundleInfo($entity_type_id); - if (empty($bundle_name) || !isset($bundles[$bundle_name])) { - // The bundle parameter is invalid. - throw new NotFoundHttpException(); - } - $values[$bundle_key] = $bundle_name; - } - $entity = $this->entityTypeManager()->getStorage($entity_type_id)->create($values); - - return $this->entityFormBuilder()->getForm($entity, 'add'); - } - - /** - * The title callback for the add form. - * - * @param string $entity_type_id - * The entity type ID. - * @param \Drupal\Core\Routing\RouteMatchInterface $route_match - * The route match. - * - * @return string - * The page title. - */ - public function addFormTitle($entity_type_id, RouteMatchInterface $route_match) { - $entity_type = $this->entityTypeManager()->getDefinition($entity_type_id); - $bundle_key = $entity_type->getKey('bundle'); - $bundles = $this->entityTypeBundleInfo->getBundleInfo($entity_type_id); - if ($bundle_key && count($bundles) > 1) { - $bundle_name = $route_match->getRawParameter($bundle_key); - $title = $this->t('Add @bundle', ['@bundle' => $bundles[$bundle_name]['label']]); - } - else { - $title = $this->t('Add @entity-type', ['@entity-type' => $entity_type->getLowercaseLabel()]); - } - - return $title; - } - - /** - * Expands the bundle information with descriptions, if known. - * - * @param array $bundles - * An array of bundle information. - * @param string $bundle_type - * The id of the bundle entity type. - * - * @return array - * The expanded array of bundle information. - */ - protected function loadBundleDescriptions(array $bundles, $bundle_type) { - // Ensure the presence of the description key. - foreach ($bundles as $bundle_name => &$bundle_info) { - $bundle_info['description'] = ''; - } - // Only bundles provided by entity types have descriptions. - if (empty($bundle_type)) { - return $bundles; - } - $bundle_entity_type = $this->entityTypeManager()->getDefinition($bundle_type); - if (!$bundle_entity_type->isSubclassOf('\Drupal\entity\Entity\EntityDescriptionInterface')) { - return $bundles; - } - $bundle_names = array_keys($bundles); - $bundle_entities = $this->entityTypeManager->getStorage($bundle_type)->loadMultiple($bundle_names); - foreach ($bundles as $bundle_name => &$bundle_info) { - if (isset($bundle_entities[$bundle_name])) { - $bundle_info['description'] = $bundle_entities[$bundle_name]->getDescription(); - } - } - - return $bundles; - } - -} diff --git a/src/Controller/RevisionController.php b/src/Controller/RevisionController.php deleted file mode 100644 index b85ee8329d8465caf9e316ee1b2a98fbb4234db2..0000000000000000000000000000000000000000 --- a/src/Controller/RevisionController.php +++ /dev/null @@ -1,36 +0,0 @@ -<?php - -/** - * @file - * Contains \Drupal\entity\Controller\RevisionController. - */ - -namespace Drupal\entity\Controller; - -use Drupal\Core\Entity\Controller\EntityViewController; -use Drupal\Core\Entity\EntityInterface; - -/** - * Provides some controllers related with entity revisions. - */ -class RevisionController extends EntityViewController { - - /** - * Provides a page to render a single entity revision. - * - * @param \Drupal\Core\Entity\EntityInterface $_entity_revision - * The Entity to be rendered. Note this variable is named $_entity_revision - * rather than $entity to prevent collisions with other named placeholders - * in the route. - * @param string $view_mode - * (optional) The view mode that should be used to display the entity. - * Defaults to 'full'. - * - * @return array - * A render array. - */ - public function view(EntityInterface $_entity_revision, $view_mode = 'full') { - return parent::view($_entity_revision, $view_mode); - } - -} diff --git a/src/Controller/RevisionOverviewController.php b/src/Controller/RevisionOverviewController.php index 5629c5af8e0d8e6a46b330ec64107da63c304abe..c92410ee19be63c32b6207adb0d3d1ef44a168da 100644 --- a/src/Controller/RevisionOverviewController.php +++ b/src/Controller/RevisionOverviewController.php @@ -13,8 +13,9 @@ use Drupal\Core\Controller\ControllerBase; use Drupal\Core\Datetime\DateFormatterInterface; use Drupal\Core\Entity\ContentEntityInterface; use Drupal\Core\Entity\EntityInterface; +use Drupal\Core\Render\RendererInterface; use Drupal\Core\Routing\RouteMatchInterface; -use Drupal\entity\Revision\EntityRevisionLogInterface; +use Drupal\Core\Entity\RevisionLogInterface; use Drupal\user\EntityOwnerInterface; use Symfony\Component\DependencyInjection\ContainerInterface; @@ -22,8 +23,7 @@ use Symfony\Component\DependencyInjection\ContainerInterface; * Provides a controller which shows the revision history. * * This controller leverages the revision controller trait, which is agnostic to - * any entity type, by using the new interface - * \Drupal\entity\Revision\EntityRevisionLogInterface. + * any entity type, by using \Drupal\Core\Entity\RevisionLogInterface. */ class RevisionOverviewController extends ControllerBase { @@ -36,21 +36,29 @@ class RevisionOverviewController extends ControllerBase { */ protected $dateFormatter; + /** + * The renderer. + * + * @var \Drupal\Core\Render\RendererInterface + */ + protected $renderer; + /** * Creates a new RevisionOverviewController instance. * * @param \Drupal\Core\Datetime\DateFormatterInterface $date_formatter * The date formatter. */ - public function __construct(DateFormatterInterface $date_formatter) { + public function __construct(DateFormatterInterface $date_formatter, RendererInterface $renderer) { $this->dateFormatter = $date_formatter; + $this->renderer = $renderer; } /** * {@inheritdoc} */ public static function create(ContainerInterface $container) { - return new static($container->get('date.formatter')); + return new static($container->get('date.formatter'), $container->get('renderer')); } /** @@ -101,17 +109,18 @@ class RevisionOverviewController extends ControllerBase { * {@inheritdoc} */ protected function getRevisionDescription(ContentEntityInterface $revision, $is_default = FALSE) { - /** @var \Drupal\Core\Entity\ContentEntityInterface|\Drupal\user\EntityOwnerInterface|\Drupal\entity\Revision\EntityRevisionLogInterface $revision */ - - if ($revision instanceof EntityRevisionLogInterface) { + /** @var \Drupal\Core\Entity\ContentEntityInterface|\Drupal\user\EntityOwnerInterface|\Drupal\Core\Entity\RevisionLogInterface $revision */ + if ($revision instanceof RevisionLogInterface) { // Use revision link to link to revisions that are not active. $date = $this->dateFormatter->format($revision->getRevisionCreationTime(), 'short'); $link = $revision->toLink($date, 'revision'); + // @todo: Simplify this when https://www.drupal.org/node/2334319 lands. $username = [ '#theme' => 'username', '#account' => $revision->getRevisionUser(), ]; + $username = $this->renderer->render($username); } else { $link = $revision->toLink($revision->label(), 'revision'); @@ -120,7 +129,7 @@ class RevisionOverviewController extends ControllerBase { } $markup = ''; - if ($revision instanceof EntityRevisionLogInterface) { + if ($revision instanceof RevisionLogInterface) { $markup = $revision->getRevisionLogMessage(); } diff --git a/src/Entity/EntityDescriptionInterface.php b/src/Entity/EntityDescriptionInterface.php deleted file mode 100644 index eb770e1d8d9c8f6ae1f9622ea6dd2c25c7d0ca1e..0000000000000000000000000000000000000000 --- a/src/Entity/EntityDescriptionInterface.php +++ /dev/null @@ -1,33 +0,0 @@ -<?php - -/** - * @file - * Contains \Drupal\entity\Entity\EntityDescriptionInterface. - */ - -namespace Drupal\entity\Entity; - -/** - * Defines the interface for entities that have a description. - */ -interface EntityDescriptionInterface { - - /** - * Gets the entity description. - * - * @return string - * The entity description. - */ - public function getDescription(); - - /** - * Sets the entity description. - * - * @param string $description - * The entity description. - * - * @return $this - */ - public function setDescription($description); - -} diff --git a/src/EntityKeysFieldsTrait.php b/src/EntityKeysFieldsTrait.php deleted file mode 100644 index 2c718cbec5a5a292b187e0fc1bfe7397dc01c1be..0000000000000000000000000000000000000000 --- a/src/EntityKeysFieldsTrait.php +++ /dev/null @@ -1,74 +0,0 @@ -<?php - -/** - * @file - * Contains \Drupal\entity\EntityKeysFieldsTrait. - */ - -namespace Drupal\entity; - -use Drupal\Core\Entity\ContentEntityTypeInterface; -use Drupal\Core\Field\BaseFieldDefinition; - -/** - * Provides base fields for entity keys. - */ -trait EntityKeysFieldsTrait { - - /** - * Returns the base field definitions for entity keys. - * - * @param \Drupal\Core\Entity\ContentEntityTypeInterface $entity_type - * The entity type. - * - * @return \Drupal\Core\Field\BaseFieldDefinition[] - */ - protected static function entityKeysBaseFieldDefinitions(ContentEntityTypeInterface $entity_type) { - $fields = []; - - if ($entity_type->hasKey('id')) { - $fields[$entity_type->getKey('id')] = BaseFieldDefinition::create('integer') - ->setLabel(t('ID')) - ->setReadOnly(TRUE) - ->setSetting('unsigned', TRUE); - } - - if ($entity_type->hasKey('uuid')) { - $fields[$entity_type->getKey('uuid')] = BaseFieldDefinition::create('uuid') - ->setLabel(t('UUID')) - ->setReadOnly(TRUE); - } - - if ($entity_type->hasKey('revision')) { - $fields[$entity_type->getKey('revision')] = BaseFieldDefinition::create('integer') - ->setLabel(t('Revision ID')) - ->setReadOnly(TRUE) - ->setSetting('unsigned', TRUE); - } - - if ($entity_type->hasKey('langcode')) { - $fields[$entity_type->getKey('langcode')] = BaseFieldDefinition::create('language') - ->setLabel(t('Language')) - ->setTranslatable(TRUE) - ->setRevisionable(TRUE) - ->setDisplayOptions('view', [ - 'type' => 'hidden', - ]) - ->setDisplayOptions('form', [ - 'type' => 'language_select', - 'weight' => 2, - ]); - } - - $bundle_entity_type_id = $entity_type->getBundleEntityType(); - if ($bundle_entity_type_id && $entity_type->hasKey('bundle')) { - $fields[$entity_type->getKey('bundle')] = BaseFieldDefinition::create('entity_reference') - ->setLabel(t('Type')) - ->setSetting('target_type', $bundle_entity_type_id) - ->setReadOnly(TRUE); - } - - return $fields; - } - -} diff --git a/src/Form/RevisionRevertForm.php b/src/Form/RevisionRevertForm.php index de2e049a50aec18a043f84690f1bba2b55a799da..a238dab98f0fdbbbbf2fc1dfd8801d784caa1d20 100644 --- a/src/Form/RevisionRevertForm.php +++ b/src/Form/RevisionRevertForm.php @@ -12,7 +12,7 @@ use Drupal\Core\Entity\EntityTypeBundleInfoInterface; use Drupal\Core\Entity\RevisionableInterface; use Drupal\Core\Form\ConfirmFormBase; use Drupal\Core\Form\FormStateInterface; -use Drupal\entity\Revision\EntityRevisionLogInterface; +use Drupal\Core\Entity\RevisionLogInterface; use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\HttpFoundation\Request; @@ -21,7 +21,7 @@ class RevisionRevertForm extends ConfirmFormBase { /** * The entity revision. * - * @var \Drupal\Core\Entity\EntityInterface|\Drupal\Core\Entity\RevisionableInterface|\Drupal\entity\Revision\EntityRevisionLogInterface + * @var \Drupal\Core\Entity\EntityInterface|\Drupal\Core\Entity\RevisionableInterface|\Drupal\Core\Entity\RevisionLogInterface */ protected $revision; @@ -73,8 +73,8 @@ class RevisionRevertForm extends ConfirmFormBase { * {@inheritdoc} */ public function getQuestion() { - if ($this->revision instanceof EntityRevisionLogInterface) { - return $this->t('Are you sure you want to revert to the revision from %revision-date?', ['%revision-date' => $this->dateFormatter->format($this->revision->getRevisionLogMessage())]); + if ($this->revision instanceof RevisionLogInterface) { + return $this->t('Are you sure you want to revert to the revision from %revision-date?', ['%revision-date' => $this->dateFormatter->format($this->revision->getRevisionCreationTime())]); } return $this->t('Are you sure you want to revert the revision?'); } @@ -119,9 +119,8 @@ class RevisionRevertForm extends ConfirmFormBase { public function submitForm(array &$form, FormStateInterface $form_state) { // The revision timestamp will be updated when the revision is saved. Keep // the original one for the confirmation message. - $this->revision = $this->prepareRevision($this->revision); - if ($this->revision instanceof EntityRevisionLogInterface) { + if ($this->revision instanceof RevisionLogInterface) { $original_revision_timestamp = $this->revision->getRevisionCreationTime(); $this->revision->setRevisionLogMessage($this->t('Copy of the revision from %date.', ['%date' => $this->dateFormatter->format($original_revision_timestamp)])); diff --git a/src/ParamConverter/EntityRevisionParamConverter.php b/src/ParamConverter/EntityRevisionParamConverter.php deleted file mode 100644 index 17315657f639d3265e29aab032da0e5068d44092..0000000000000000000000000000000000000000 --- a/src/ParamConverter/EntityRevisionParamConverter.php +++ /dev/null @@ -1,53 +0,0 @@ -<?php - -/** - * @file - * Contains \Drupal\entity\ParamConverter\EntityRevisionParamConverter. - */ - -namespace Drupal\entity\ParamConverter; - -use Drupal\Core\Entity\EntityManagerInterface; -use Drupal\Core\Entity\EntityTypeManagerInterface; -use Drupal\Core\ParamConverter\ParamConverterInterface; -use Symfony\Component\Routing\Route; - -/** - * Parameter converter for single revisions. - */ -class EntityRevisionParamConverter implements ParamConverterInterface { - - /** - * The entity type manager. - * - * @var \Drupal\Core\Entity\EntityTypeManagerInterface - */ - protected $entityTypeManager; - - /** - * Creates a new EntityRevisionParamConverter instance. - * - * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager - * The entity type manager. - */ - public function __construct(EntityTypeManagerInterface $entity_type_manager) { - $this->entityTypeManager = $entity_type_manager; - } - - /** - * {@inheritdoc} - */ - public function convert($value, $definition, $name, array $defaults) { - list (, $entity_type_id) = explode(':', $definition['type']); - $entity_storage = $this->entityTypeManager->getStorage($entity_type_id); - return $entity_storage->loadRevision($value); - } - - /** - * {@inheritdoc} - */ - public function applies($definition, $name, Route $route) { - return isset($definition['type']) && strpos($definition['type'], 'entity_revision:') !== FALSE; - } - -} diff --git a/src/Plugin/views/field/RenderedEntity.php b/src/Plugin/views/field/RenderedEntity.php deleted file mode 100644 index b12163b0a5fcab33f9e2e9b7b0a2ba98d236087b..0000000000000000000000000000000000000000 --- a/src/Plugin/views/field/RenderedEntity.php +++ /dev/null @@ -1,213 +0,0 @@ -<?php - -/** - * @file - * Contains \Drupal\entity\Plugin\views\field\RenderedEntity. - */ - -namespace Drupal\entity\Plugin\views\field; - -use Drupal\Core\Cache\CacheableDependencyInterface; -use Drupal\Core\Entity\EntityManagerInterface; -use Drupal\Core\Form\FormStateInterface; -use Drupal\Core\Language\LanguageManagerInterface; -use Drupal\views\Entity\Render\EntityTranslationRenderTrait; -use Drupal\views\ResultRow; -use Drupal\views\Plugin\views\field\FieldPluginBase; -use Symfony\Component\DependencyInjection\ContainerInterface; - -/** - * Provides a field handler which renders an entity in a certain view mode. - * - * @ingroup views_field_handlers - * - * @ViewsField("rendered_entity") - */ -class RenderedEntity extends FieldPluginBase implements CacheableDependencyInterface { - - use EntityTranslationRenderTrait; - - /** - * The entity manager. - * - * @var \Drupal\Core\Entity\EntityManagerInterface - */ - protected $entityManager; - - /** - * The language manager. - * - * @var \Drupal\Core\Language\LanguageManagerInterface - */ - protected $languageManager; - - /** - * Constructs a new RenderedEntity object. - * - * @param array $configuration - * A configuration array containing information about the plugin instance. - * @param string $plugin_id - * The plugin_id for the plugin instance. - * @param array $plugin_definition - * The plugin implementation definition. - * @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager - * The entity manager. - * @param \Drupal\Core\Language\LanguageManagerInterface $language_manager - * The language manager. - */ - public function __construct(array $configuration, $plugin_id, array $plugin_definition, EntityManagerInterface $entity_manager, LanguageManagerInterface $language_manager) { - parent::__construct($configuration, $plugin_id, $plugin_definition); - - $this->entityManager = $entity_manager; - $this->languageManager = $language_manager; - } - - /** - * {@inheritdoc} - */ - public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) { - return new static( - $configuration, - $plugin_id, - $plugin_definition, - $container->get('entity.manager'), - $container->get('language_manager') - ); - } - - /** - * {@inheritdoc} - */ - public function usesGroupBy() { - return FALSE; - } - - /** - * {@inheritdoc} - */ - public function defineOptions() { - $options = parent::defineOptions(); - $options['view_mode'] = ['default' => 'default']; - - return $options; - } - - /** - * {@inheritdoc} - */ - public function buildOptionsForm(&$form, FormStateInterface $form_state) { - parent::buildOptionsForm($form, $form_state); - - $form['view_mode'] = [ - '#type' => 'select', - '#options' => $this->entityManager->getViewModeOptions($this->getEntityTypeId()), - '#title' => $this->t('View mode'), - '#default_value' => $this->options['view_mode'], - ]; - } - - /** - * {@inheritdoc} - */ - public function render(ResultRow $values) { - $entity = $this->getEntityTranslation($this->getEntity($values), $values); - $build = []; - if (isset($entity)) { - $access = $entity->access('view', NULL, TRUE); - $build['#access'] = $access; - if ($access->isAllowed()) { - $view_builder = $this->entityManager->getViewBuilder($this->getEntityTypeId()); - $build += $view_builder->view($entity, $this->options['view_mode']); - } - } - return $build; - } - - /** - * {@inheritdoc} - */ - public function getCacheContexts() { - return []; - } - - /** - * {@inheritdoc} - */ - public function getCacheTags() { - $view_display_storage = $this->entityManager->getStorage('entity_view_display'); - $view_displays = $view_display_storage->loadMultiple($view_display_storage - ->getQuery() - ->condition('targetEntityType', $this->getEntityTypeId()) - ->execute()); - - $tags = []; - foreach ($view_displays as $view_display) { - $tags = array_merge($tags, $view_display->getCacheTags()); - } - return $tags; - } - - /** - * {@inheritdoc} - */ - public function getCacheMaxAge() { - return 0; - } - - /** - * {@inheritdoc} - */ - public function query() { - // We purposefully do not call parent::query() because we do not want the - // default query behavior for Views fields. Instead, let the entity - // translation renderer provide the correct query behavior. - if ($this->languageManager->isMultilingual()) { - $this->getEntityTranslationRenderer()->query($this->query, $this->relationship); - } - } - - /** - * {@inheritdoc} - */ - public function getEntityTypeId() { - return $this->getEntityType(); - } - - /** - * {@inheritdoc} - */ - protected function getEntityManager() { - return $this->entityManager; - } - - /** - * {@inheritdoc} - */ - protected function getLanguageManager() { - return $this->languageManager; - } - - /** - * {@inheritdoc} - */ - protected function getView() { - return $this->view; - } - - /** - * {@inheritdoc} - */ - public function calculateDependencies() { - $dependencies = parent::calculateDependencies(); - - $view_mode = $this->entityManager - ->getStorage('entity_view_mode') - ->load($this->getEntityTypeId() . '.' . $this->options['view_mode']); - if ($view_mode) { - $dependencies[$view_mode->getConfigDependencyKey()][] = $view_mode->getConfigDependencyName(); - } - - return $dependencies; - } - -} diff --git a/src/Revision/EntityRevisionLogInterface.php b/src/Revision/EntityRevisionLogInterface.php deleted file mode 100644 index f02ba92f8ef0d6fc0cd1ad9b64e7f98060ed4fbe..0000000000000000000000000000000000000000 --- a/src/Revision/EntityRevisionLogInterface.php +++ /dev/null @@ -1,92 +0,0 @@ -<?php - -/** - * @file - * Contains \Drupal\entity\Revision\EntityRevisionLogInterface. - */ - -namespace Drupal\entity\Revision; - -use Drupal\user\UserInterface; - -/** - * Defines an entity type with create time/author/log information for revisions. - */ -interface EntityRevisionLogInterface { - - /** - * Gets the entity revision creation timestamp. - * - * @return int|NULL - * The UNIX timestamp of when this revision was created. Return NULL if the - * entity type does not support revision create time. - */ - public function getRevisionCreationTime(); - - /** - * Sets the entity revision creation timestamp. - * - * @param int $timestamp - * The UNIX timestamp of when this revision was created. - * - * @return $this - */ - public function setRevisionCreationTime($timestamp); - - /** - * Gets the entity revision author. - * - * @return \Drupal\user\UserInterface|NULL - * The user entity for the revision author. Return NULL if the entity type - * doesn't support revision authors. - */ - public function getRevisionUser(); - - /** - * Sets the entity revision author. - * - * @param \Drupal\user\UserInterface $account - * The user account of the revision author. - * - * @return $this - */ - public function setRevisionUser(UserInterface $account); - - /** - * Gets the entity revision author ID. - * - * @return int - * The user ID. - */ - public function getRevisionUserId(); - - /** - * Sets the entity revision author by ID. - * - * @param int $user_id - * The user ID of the revision author. - * - * @return $this - */ - public function setRevisionUserId($user_id); - - /** - * Returns the entity revision log message. - * - * @return string|NULL - * The revision log message. Return NULL if the entity type doesn't support - * revision logs. - */ - public function getRevisionLogMessage(); - - /** - * Sets the entity revision log message. - * - * @param string $revision_log_message - * The revision log message. - * - * @return $this - */ - public function setRevisionLogMessage($revision_log_message); - -} diff --git a/src/Revision/EntityRevisionLogTrait.php b/src/Revision/EntityRevisionLogTrait.php deleted file mode 100644 index cc27b1a2f967227ae10be456e5d2debdddf315e9..0000000000000000000000000000000000000000 --- a/src/Revision/EntityRevisionLogTrait.php +++ /dev/null @@ -1,113 +0,0 @@ -<?php - -/** - * @file - * Contains \Drupal\entity\Revision\EntityRevisionLogTrait. - */ - -namespace Drupal\entity\Revision; - -use Drupal\Core\Field\BaseFieldDefinition; -use Drupal\user\UserInterface; - -/** - * Provides a trait implementing \Drupal\entity\Revision\EntityRevisionLogInterface. - */ -trait EntityRevisionLogTrait { - - /** - * Provides the base fields for the entity revision log trait. - * - * @return \Drupal\Core\Field\BaseFieldDefinition[] - */ - protected static function entityRevisionLogBaseFieldDefinitions() { - $fields = []; - - $fields['revision_created'] = BaseFieldDefinition::create('created') - ->setLabel(t('Revision create time')) - ->setDescription(t('The time that the current revision was created.')) - ->setRevisionable(TRUE); - - $fields['revision_user'] = BaseFieldDefinition::create('entity_reference') - ->setLabel(t('Revision user')) - ->setDescription(t('The user ID of the author of the current revision.')) - ->setSetting('target_type', 'user') - ->setRevisionable(TRUE); - - $fields['revision_log_message'] = BaseFieldDefinition::create('string_long') - ->setLabel(t('Revision log message')) - ->setDescription(t('Briefly describe the changes you have made.')) - ->setRevisionable(TRUE) - ->setDefaultValue('') - ->setDisplayOptions('form', [ - 'type' => 'string_textarea', - 'weight' => 25, - 'settings' => [ - 'rows' => 4, - ], - ]); - - return $fields; - } - - /** - * {@inheritdoc} - */ - public function getRevisionCreationTime() { - return $this->revision_created->value; - } - - /** - * {@inheritdoc} - */ - public function setRevisionCreationTime($timestamp) { - $this->revision_created->value = $timestamp; - return $this; - } - - /** - * {@inheritdoc} - */ - public function getRevisionUser() { - return $this->revision_user->entity; - } - - /** - * {@inheritdoc} - */ - public function setRevisionUser(UserInterface $account) { - $this->revision_user->entity = $account; - return $this; - } - - /** - * {@inheritdoc} - */ - public function getRevisionUserId() { - return $this->revision_user->target_id; - } - - /** - * {@inheritdoc} - */ - public function setRevisionUserId($user_id) { - $this->revision_user->target_id = $user_id; - return $this; - } - - /** - * {@inheritdoc} - */ - public function getRevisionLogMessage() { - return $this->revision_log_message->value; - } - - /** - * {@inheritdoc} - */ - public function setRevisionLogMessage($revision_log_message) { - $this->revision_log_message->value = $revision_log_message; - return $this; - } - -} diff --git a/src/Revision/RevisionableContentEntityBase.php b/src/Revision/RevisionableContentEntityBase.php index 2b6ae620e3bea787a511879385da47451e1f4e99..5b8a111ae5ad57eb1114554143398fb42e005ccf 100644 --- a/src/Revision/RevisionableContentEntityBase.php +++ b/src/Revision/RevisionableContentEntityBase.php @@ -7,12 +7,13 @@ namespace Drupal\entity\Revision; +use Drupal\Core\Entity\RevisionableContentEntityBase as BaseRevisionableContentEntityBase; use Drupal\Core\Entity\ContentEntityBase; /** - * Provides an entity class with revisions. + * Improves the url route handling of core's revisionable content entity base. */ -abstract class RevisionableContentEntityBase extends ContentEntityBase { +abstract class RevisionableContentEntityBase extends BaseRevisionableContentEntityBase { /** * {@inheritdoc} diff --git a/src/RouteEnhancer/EntityRevisionRouteEnhancer.php b/src/RouteEnhancer/EntityRevisionRouteEnhancer.php deleted file mode 100644 index 202552e4369c01a64139f4c83727117f4083e2d4..0000000000000000000000000000000000000000 --- a/src/RouteEnhancer/EntityRevisionRouteEnhancer.php +++ /dev/null @@ -1,53 +0,0 @@ -<?php - -/** - * @file - * Contains \Drupal\entity\RouteEnhancer\EntityRevisionRouteEnhancer. - */ - -namespace Drupal\entity\RouteEnhancer; - -use Drupal\Core\Routing\Enhancer\RouteEnhancerInterface; -use Symfony\Cmf\Component\Routing\RouteObjectInterface; -use Symfony\Component\HttpFoundation\Request; -use Symfony\Component\Routing\Route; - -/** - * Adds _entity_revision to the request attributes, if possible. - */ -class EntityRevisionRouteEnhancer implements RouteEnhancerInterface { - - /** - * {@inheritdoc} - */ - public function applies(Route $route) { - // Check whether there is any entity revision parameter. - $parameters = $route->getOption('parameters') ?: []; - foreach ($parameters as $info) { - if (isset($info['type']) && strpos($info['type'], 'entity_revision:') === 0) { - return TRUE; - } - } - return FALSE; - } - - /** - * {@inheritdoc} - */ - public function enhance(array $defaults, Request $request) { - /** @var \Symfony\Component\Routing\Route $route */ - $route = $defaults[RouteObjectInterface::ROUTE_OBJECT]; - $options = $route->getOptions(); - if (isset($options['parameters'])) { - foreach ($options['parameters'] as $name => $details) { - if (!empty($details['type']) && strpos($details['type'], 'entity_revision:') !== FALSE) { - $defaults['_entity_revision'] = $defaults[$name]; - break; - } - } - } - - return $defaults; - } - -} diff --git a/src/Routing/AdminCreateHtmlRouteProvider.php b/src/Routing/AdminCreateHtmlRouteProvider.php deleted file mode 100644 index 0161715f55278fdbfcf0a03a3ac84e869f761bc2..0000000000000000000000000000000000000000 --- a/src/Routing/AdminCreateHtmlRouteProvider.php +++ /dev/null @@ -1,37 +0,0 @@ -<?php - -/** - * @file - * Contains \Drupal\entity\Routing\AdminCreateHtmlRouteProvider. - */ - -namespace Drupal\entity\Routing; - -use Drupal\Core\Entity\EntityTypeInterface; - -/** - * Provides HTML routes for creating entities using the administrative theme. - */ -class AdminCreateHtmlRouteProvider extends CreateHtmlRouteProvider { - - /** - * {@inheritdoc} - */ - protected function addPageRoute(EntityTypeInterface $entity_type) { - if ($route = parent::addPageRoute($entity_type)) { - $route->setOption('_admin_route', TRUE); - return $route; - } - } - - /** - * {@inheritdoc} - */ - protected function addFormRoute(EntityTypeInterface $entity_type) { - if ($route = parent::addFormRoute($entity_type)) { - $route->setOption('_admin_route', TRUE); - return $route; - } - } - -} diff --git a/src/Routing/CreateHtmlRouteProvider.php b/src/Routing/CreateHtmlRouteProvider.php deleted file mode 100644 index 221b598e906d7403d4a814d0308f06df87132169..0000000000000000000000000000000000000000 --- a/src/Routing/CreateHtmlRouteProvider.php +++ /dev/null @@ -1,85 +0,0 @@ -<?php - -/** - * @file - * Contains \Drupal\entity\Routing\CreateHtmlRouteProvider. - */ - -namespace Drupal\entity\Routing; - -use Drupal\Core\Entity\EntityTypeInterface; -use Drupal\Core\Entity\Routing\EntityRouteProviderInterface; -use Symfony\Component\Routing\Route; -use Symfony\Component\Routing\RouteCollection; - -/** - * Provides HTML routes for creating entities. - * - * This class provides the following routes for entities, with title callbacks: - * - add-page - * - add-form - * - * @see \Drupal\entity\Routing\AdminCreateHtmlRouteProvider. - */ -class CreateHtmlRouteProvider implements EntityRouteProviderInterface { - - /** - * {@inheritdoc} - */ - public function getRoutes(EntityTypeInterface $entity_type) { - $routes = new RouteCollection(); - if ($route = $this->addPageRoute($entity_type)) { - $routes->add('entity.' . $entity_type->id() . '.add_page', $route); - } - if ($route = $this->addFormRoute($entity_type)) { - $routes->add('entity.' . $entity_type->id() . '.add_form', $route); - } - - return $routes; - } - - /** - * Returns the add page route. - * - * Built only for entity types that have bundles. - * - * @param \Drupal\Core\Entity\EntityTypeInterface $entity_type - * The entity type. - * - * @return \Symfony\Component\Routing\Route|null - * The generated route, if available. - */ - protected function addPageRoute(EntityTypeInterface $entity_type) { - if ($entity_type->hasLinkTemplate('add-page') && $entity_type->getKey('bundle')) { - $route = new Route($entity_type->getLinkTemplate('add-page')); - $route->setDefault('_controller', '\Drupal\entity\Controller\EntityCreateController::addPage'); - $route->setDefault('_title_callback', '\Drupal\entity\Controller\EntityCreateController::addPageTitle'); - $route->setDefault('entity_type_id', $entity_type->id()); - $route->setRequirement('_entity_create_access', $entity_type->id()); - - return $route; - } - } - - /** - * Returns the add 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 addFormRoute(EntityTypeInterface $entity_type) { - if ($entity_type->hasLinkTemplate('add-form')) { - $route = new Route($entity_type->getLinkTemplate('add-form')); - $route->setDefault('_controller', '\Drupal\entity\Controller\EntityCreateController::addForm'); - $route->setDefault('_title_callback', '\Drupal\entity\Controller\EntityCreateController::addFormTitle'); - $route->setDefault('entity_type_id', $entity_type->id()); - $route->setRequirement('_entity_create_access', $entity_type->id()); - - return $route; - } - } - -} diff --git a/src/Routing/RevisionRouteProvider.php b/src/Routing/RevisionRouteProvider.php index 33d2766f9d3af38c54c6abe78705b7b7dad3a9cf..7e3afe227a7b4766a6d663137b272138d9cb1350 100644 --- a/src/Routing/RevisionRouteProvider.php +++ b/src/Routing/RevisionRouteProvider.php @@ -51,7 +51,7 @@ class RevisionRouteProvider implements EntityRouteProviderInterface { $entity_type_id = $entity_type->id(); $route = new Route($entity_type->getLinkTemplate('revision')); $route->addDefaults([ - '_controller' => '\Drupal\entity\Controller\RevisionController::view', + '_controller' => '\Drupal\Core\Entity\Controller\EntityViewController::viewRevision', '_title_callback' => '\Drupal\Core\Entity\Controller\EntityController::title', ]); $route->addRequirements([ diff --git a/src/Tests/Plugin/views/field/RenderedEntityTest.php b/src/Tests/Plugin/views/field/RenderedEntityTest.php deleted file mode 100644 index ff753048214241bc83449544bf19f1e971719607..0000000000000000000000000000000000000000 --- a/src/Tests/Plugin/views/field/RenderedEntityTest.php +++ /dev/null @@ -1,221 +0,0 @@ -<?php - -/** - * @file - * Contains \Drupal\entity\Tests\Plugin\views\field\RenderedEntityTest. - */ - -namespace Drupal\entity\Tests\Plugin\views\field; - -use Drupal\Core\Entity\Entity\EntityViewDisplay; -use Drupal\entity_test\Entity\EntityTest; -use Drupal\field\Entity\FieldConfig; -use Drupal\field\Entity\FieldStorageConfig; -use Drupal\user\Entity\Role; -use Drupal\user\Entity\User; -use Drupal\views\Entity\View; -use Drupal\views\Tests\ViewKernelTestBase; -use Drupal\views\Tests\ViewTestData; -use Drupal\views\Views; -use Drupal\Core\Entity\Entity\EntityViewMode; - -/** - * Tests the Drupal\entity\Plugin\views\field\RenderedEntity handler. - * - * @group entity - */ -class RenderedEntityTest extends ViewKernelTestBase { - - /** - * Modules to enable. - * - * @var array - */ - public static $modules = ['entity_test', 'entity_module_test', 'field']; - - /** - * Views used by this test. - * - * @var array - */ - public static $testViews = ['test_entity_rendered']; - - /** - * The logged in user. - * - * @var \Drupal\user\UserInterface - */ - protected $user; - - /** - * {@inheritdoc} - */ - protected function setUp($import_test_views = TRUE) { - parent::setUp($import_test_views); - - if ($import_test_views) { - ViewTestData::createTestViews(get_class($this), ['entity_module_test']); - } - } - - /** - * {@inheritdoc} - */ - protected function setUpFixtures() { - $this->installEntitySchema('user'); - $this->installEntitySchema('entity_test'); - $this->installConfig(['entity_test']); - - EntityViewMode::create([ - 'id' => 'entity_test.foobar', - 'targetEntityType' => 'entity_test', - 'status' => TRUE, - 'enabled' => TRUE, - 'label' => 'My view mode', - ])->save(); - - $display = EntityViewDisplay::create([ - 'targetEntityType' => 'entity_test', - 'bundle' => 'entity_test', - 'mode' => 'foobar', - 'label' => 'My view mode', - 'status' => TRUE, - ]); - $display->save(); - - $field_storage = FieldStorageConfig::create([ - 'field_name' => 'test_field', - 'entity_type' => 'entity_test', - 'type' => 'string', - ]); - $field_storage->save(); - - $field_config = FieldConfig::create([ - 'field_name' => 'test_field', - 'entity_type' => 'entity_test', - 'bundle' => 'entity_test', - ]); - $field_config->save(); - - // Create some test entities. - for ($i = 1; $i <= 3; $i++) { - EntityTest::create([ - 'name' => "Article title $i", - 'test_field' => "Test $i", - ])->save(); - } - - $role = Role::create([ - 'id' => 'test_role', - ]); - $role->grantPermission('bypass node access'); - $role->save(); - $this->user = User::create([ - 'name' => 'test user', - ]); - $this->user->addRole($role->id()); - $this->user->save(); - - parent::setUpFixtures(); - } - - /** - * Tests the default rendered entity output. - */ - public function testRenderedEntityWithoutField() { - \Drupal::currentUser()->setAccount($this->user); - - EntityViewDisplay::load('entity_test.entity_test.foobar') - ->removeComponent('test_field') - ->save(); - - // The view should not display the body field. - $view = Views::getView('test_field_entity_test_rendered'); - $build = [ - '#type' => 'view', - '#name' => 'test_field_entity_test_rendered', - '#view' => $view, - '#display_id' => 'default', - ]; - $renderer = \Drupal::service('renderer'); - $renderer->renderPlain($build); - for ($i = 1; $i <= 3; $i++) { - $view_field = $view->style_plugin->getField($i - 1, 'rendered_entity'); - $search_result = strpos($view_field, "Test $i") !== FALSE; - $this->assertFalse($search_result, "The text 'Test $i' not found in the view."); - } - - $this->assertConfigDependencies($view->storage); - $this->assertCacheabilityMetadata($build); - } - - /** - * Tests the rendered entity output with the body field configured to show. - */ - public function testRenderedEntityWithField() { - \Drupal::currentUser()->setAccount($this->user); - - // Show the body on the node.x.foobar view mode. - EntityViewDisplay::load('entity_test.entity_test.foobar')->setComponent('test_field', ['type' => 'string', 'label' => 'above'])->save(); - - // The view should display the body field. - $view = Views::getView('test_field_entity_test_rendered'); - $build = [ - '#type' => 'view', - '#name' => 'test_field_entity_test_rendered', - '#view' => $view, - '#display_id' => 'default', - ]; - $renderer = \Drupal::service('renderer'); - $renderer->renderPlain($build); - for ($i = 1; $i <= 3; $i++) { - $view_field = $view->style_plugin->getField($i - 1, 'rendered_entity'); - $search_result = strpos($view_field, "Test $i") !== FALSE; - $this->assertTrue($search_result, "The text 'Test $i' found in the view."); - } - - $this->assertConfigDependencies($view->storage); - $this->assertCacheabilityMetadata($build); - } - - /** - * Ensures that the expected cacheability metadata is applied. - * - * @param array $build - * The render array - */ - protected function assertCacheabilityMetadata($build) { - $this->assertEqual([ - 'config:core.entity_view_display.entity_test.entity_test.foobar', - 'config:views.view.test_field_entity_test_rendered', - 'entity_test:1', - 'entity_test:2', - 'entity_test:3', - 'entity_test_list', - 'entity_test_view', - ], $build['#cache']['tags']); - - $this->assertEqual([ - 'entity_test_view_grants', - 'languages:language_interface', - 'theme', - 'url.query_args', - 'user.permissions', - ], $build['#cache']['contexts']); - } - - /** - * Ensures that the config dependencies are calculated the right way. - * - * @param \Drupal\views\Entity\View $storage - * The view storage. - */ - protected function assertConfigDependencies(View $storage) { - $storage->calculateDependencies(); - $this->assertEqual([ - 'config' => ['core.entity_view_mode.entity_test.foobar'], - 'module' => ['entity_test'], - ], $storage->getDependencies()); - } - -} diff --git a/templates/entity-add-list.html.twig b/templates/entity-add-list.html.twig deleted file mode 100644 index 55970efd08b32e55aa292407afe5ee8c392fc9e9..0000000000000000000000000000000000000000 --- a/templates/entity-add-list.html.twig +++ /dev/null @@ -1,31 +0,0 @@ -{# -/** - * @file - * Default theme implementation to present a list of available bundles. - * - * Available variables: - * - create_bundle_url: The url to the bundle creation page. - * - bundle_type_label: The lowercase label of the bundle entity type. - * - bundles: A list of bundles, each with the following properties: - * - add_link: link to create an entity of this bundle. - * - description: Bundle description. - * - * @see template_preprocess_entity_add_list() - * - * @ingroup themeable - */ -#} -{% if bundles is not empty %} - <dl> - {% for bundle in bundles %} - <dt>{{ bundle.add_link }}</dt> - <dd>{{ bundle.description }}</dd> - {% endfor %} - </dl> -{% else %} - <p> - {% trans %} - Go to the <a href="{{ create_bundle_url }}">{{ bundle_type_label }} creation page</a> to add a new {{ bundle_type_label }}. - {% endtrans %} - </p> -{% endif %} diff --git a/tests/modules/entity_module_test/src/Entity/EnhancedEntity.php b/tests/modules/entity_module_test/src/Entity/EnhancedEntity.php index d199f3d653743818bc5cab93a4194190e1139bf5..e0685e4e751a36d5f172f120c5845e4898d37a4a 100644 --- a/tests/modules/entity_module_test/src/Entity/EnhancedEntity.php +++ b/tests/modules/entity_module_test/src/Entity/EnhancedEntity.php @@ -9,8 +9,6 @@ namespace Drupal\entity_module_test\Entity; use Drupal\Core\Entity\EntityTypeInterface; use Drupal\Core\Field\BaseFieldDefinition; -use Drupal\entity\EntityKeysFieldsTrait; -use Drupal\entity\Revision\EntityRevisionLogTrait; use Drupal\entity\Revision\RevisionableContentEntityBase; /** @@ -29,7 +27,6 @@ use Drupal\entity\Revision\RevisionableContentEntityBase; * "route_provider" = { * "html" = "\Drupal\Core\Entity\Routing\DefaultHtmlRouteProvider", * "revision" = "\Drupal\entity\Routing\RevisionRouteProvider", - * "create" = "\Drupal\entity\Routing\CreateHtmlRouteProvider", * "delete-multiple" = "\Drupal\entity\Routing\DeleteMultipleRouteProvider", * }, * "list_builder" = "\Drupal\Core\Entity\EntityListBuilder", @@ -62,17 +59,11 @@ use Drupal\entity\Revision\RevisionableContentEntityBase; */ class EnhancedEntity extends RevisionableContentEntityBase { - use EntityRevisionLogTrait; - use EntityKeysFieldsTrait; - /** * {@inheritdoc} */ public static function baseFieldDefinitions(EntityTypeInterface $entity_type) { - $fields = []; - - $fields += static::entityKeysBaseFieldDefinitions($entity_type); - $fields += static::entityRevisionLogBaseFieldDefinitions(); + $fields = parent::baseFieldDefinitions($entity_type); $fields['name'] = BaseFieldDefinition::create('string') ->setLabel('Name') diff --git a/tests/modules/entity_module_test/src/Entity/EnhancedEntityBundle.php b/tests/modules/entity_module_test/src/Entity/EnhancedEntityBundle.php index efa095b4b3fa44c454b5e48bb601bfa2e1b5b0cb..21c720292505360a6a444eecb69dc05775412489 100644 --- a/tests/modules/entity_module_test/src/Entity/EnhancedEntityBundle.php +++ b/tests/modules/entity_module_test/src/Entity/EnhancedEntityBundle.php @@ -8,7 +8,7 @@ namespace Drupal\entity_module_test\Entity; use Drupal\Core\Config\Entity\ConfigEntityBundleBase; -use Drupal\entity\Entity\EntityDescriptionInterface; +use Drupal\Core\Entity\EntityDescriptionInterface; use Drupal\entity\Entity\RevisionableEntityBundleInterface; /** @@ -17,11 +17,6 @@ use Drupal\entity\Entity\RevisionableEntityBundleInterface; * @ConfigEntityType( * id = "entity_test_enhanced_bundle", * label = @Translation("Entity test with enhancments - Bundle"), - * handlers = { - * "route_provider" = { - * "create" = "\Drupal\entity\Routing\CreateHtmlRouteProvider", - * }, - * }, * admin_permission = "administer entity_test_enhanced", * config_prefix = "entity_test_enhanced_bundle", * bundle_of = "entity_test_enhanced", @@ -34,9 +29,6 @@ use Drupal\entity\Entity\RevisionableEntityBundleInterface; * "label", * "description" * }, - * links = { - * "add-form" = "/entity_test_enhanced_bundle/add", - * }, * ) */ class EnhancedEntityBundle extends ConfigEntityBundleBase implements EntityDescriptionInterface, RevisionableEntityBundleInterface { diff --git a/tests/modules/entity_module_test/test_views/views.view.test_field_entity_test_rendered.yml b/tests/modules/entity_module_test/test_views/views.view.test_field_entity_test_rendered.yml deleted file mode 100644 index 541ee969306fd6c9efc62c1057f8988eac093ede..0000000000000000000000000000000000000000 --- a/tests/modules/entity_module_test/test_views/views.view.test_field_entity_test_rendered.yml +++ /dev/null @@ -1,161 +0,0 @@ -langcode: en -status: true -dependencies: - module: - - entity_test - - user -id: test_field_entity_test_rendered -label: 'Test Rendered entity test' -module: views -description: '' -tag: '' -base_table: entity_test -base_field: id -core: 8.x -display: - default: - display_plugin: default - id: default - display_title: Master - position: 0 - display_options: - access: - type: none - options: { } - cache: - type: none - options: { } - query: - type: views_query - options: - disable_sql_rewrite: false - distinct: false - replica: false - query_comment: '' - query_tags: { } - exposed_form: - type: basic - options: - submit_button: Apply - reset_button: false - reset_button_label: Reset - exposed_sorts_label: 'Sort by' - expose_sort_order: true - sort_asc_label: Asc - sort_desc_label: Desc - pager: - type: full - options: - items_per_page: 10 - offset: 0 - id: 0 - total_pages: null - expose: - items_per_page: false - items_per_page_label: 'Items per page' - items_per_page_options: '5, 10, 25, 50' - items_per_page_options_all: false - items_per_page_options_all_label: '- All -' - offset: false - offset_label: Offset - tags: - previous: '‹ Previous' - next: 'Next ›' - first: '« First' - last: 'Last »' - quantity: 9 - style: - type: default - options: - grouping: { } - row_class: '' - default_row_class: true - uses_fields: false - row: - type: fields - options: - inline: { } - separator: '' - hide_empty: false - default_field_elements: true - fields: - rendered_entity: - id: rendered_entity - table: entity_test - field: rendered_entity - relationship: none - group_type: group - admin_label: '' - label: '' - exclude: false - alter: - alter_text: false - text: '' - make_link: false - path: '' - absolute: false - external: false - replace_spaces: false - path_case: none - trim_whitespace: false - alt: '' - rel: '' - link_class: '' - prefix: '' - suffix: '' - target: '' - nl2br: false - max_length: 0 - word_boundary: true - ellipsis: true - more_link: false - more_link_text: '' - more_link_path: '' - strip_tags: false - trim: false - preserve_tags: '' - html: false - element_type: '' - element_class: '' - element_label_type: '' - element_label_class: '' - element_label_colon: false - element_wrapper_type: '' - element_wrapper_class: '' - element_default_classes: true - empty: '' - hide_empty: false - empty_zero: false - hide_alter_empty: true - view_mode: foobar - entity_type: entity_test - plugin_id: rendered_entity - filters: { } - sorts: - id: - id: id - table: entity_test - field: id - relationship: none - group_type: group - admin_label: '' - order: ASC - exposed: false - expose: - label: '' - entity_type: entity_test - entity_field: nid - plugin_id: standard - header: { } - footer: { } - empty: { } - relationships: { } - arguments: { } - display_extenders: { } - cache_metadata: - max-age: 0 - contexts: - - 'languages:language_interface' - - url.query_args - - user.permissions - tags: { } diff --git a/tests/src/Functional/CreateUITest.php b/tests/src/Functional/CreateUITest.php deleted file mode 100644 index dbf467ccf136c0430684a3137378a22793414f0d..0000000000000000000000000000000000000000 --- a/tests/src/Functional/CreateUITest.php +++ /dev/null @@ -1,97 +0,0 @@ -<?php - -/** - * @file - * Contains \Drupal\Tests\entity\Functional\CreateUITest. - */ - -namespace Drupal\Tests\entity\Functional; - -use Drupal\entity_module_test\Entity\EnhancedEntity; -use Drupal\entity_module_test\Entity\EnhancedEntityBundle; -use Drupal\simpletest\BrowserTestBase; - -/** - * Tests the entity creation UI provided by EntityCreateController. - * - * @group entity - * @runTestsInSeparateProcesses - * @preserveGlobalState disabled - */ -class CreateUITest extends BrowserTestBase { - - /** - * Modules to enable. - * - * @var array - */ - public static $modules = ['entity_module_test', 'user', 'entity']; - - /** - * {@inheritdoc} - */ - protected function setUp() { - parent::setUp(); - - EnhancedEntityBundle::create([ - 'id' => 'first', - 'label' => 'First', - 'description' => 'The first bundle', - ])->save(); - $account = $this->drupalCreateUser(['administer entity_test_enhanced']); - $this->drupalLogin($account); - } - - /** - * Tests the add page. - */ - public function testAddPage() { - // This test revealed that if the first bundle gets created in testAddPage - // before drupalGet(), the built cache won't get reset when the second - // bundle is created. This is a BrowserTestBase specific bug. - // @todo Remove comment when the bug is fixed. - - // When only one bundle exists, the add page should redirect to the form. - $this->drupalGet('/entity_test_enhanced/add'); - $this->assertSession()->addressEquals('/entity_test_enhanced/add/first'); - - EnhancedEntityBundle::create([ - 'id' => 'second', - 'label' => 'Second', - 'description' => 'The <b>second</b> bundle', - ])->save(); - $this->drupalGet('/entity_test_enhanced/add'); - $assert = $this->assertSession(); - $assert->addressEquals('/entity_test_enhanced/add'); - $assert->statusCodeEquals(200); - $assert->elementTextContains('css', '.page-title', 'Add entity test with enhancements'); - // Confirm the presence of unescaped descriptions. - $assert->responseContains('The first bundle'); - $assert->responseContains('The <b>second</b> bundle'); - // Validate the links. - $link = $this->getSession()->getPage()->findLink('First'); - $this->assertEquals('/entity_test_enhanced/add/first', $link->getAttribute('href')); - $link = $this->getSession()->getPage()->findLink('Second'); - $this->assertEquals('/entity_test_enhanced/add/second', $link->getAttribute('href')); - } - - /** - * Tests the add form. - */ - public function testAddForm() { - $this->drupalGet('/entity_test_enhanced/add/first'); - $assert = $this->assertSession(); - $assert->elementTextContains('css', '.page-title', 'Add entity test with enhancements'); - $assert->elementExists('css', 'form.entity-test-enhanced-first-add-form'); - - // In case of multiple bundles, the current one is a part of the page title. - EnhancedEntityBundle::create([ - 'id' => 'second', - 'label' => 'Second', - 'description' => 'The <b>second</b> bundle', - ])->save(); - $this->drupalGet('/entity_test_enhanced/add/first'); - $this->assertSession()->elementTextContains('css', '.page-title', 'Add First'); - } - -} diff --git a/tests/src/Kernel/EntityRevisionLogTraitTest.php b/tests/src/Kernel/EntityRevisionLogTraitTest.php deleted file mode 100644 index e872ac70f93ad99170a499fae562fecfdcf496ac..0000000000000000000000000000000000000000 --- a/tests/src/Kernel/EntityRevisionLogTraitTest.php +++ /dev/null @@ -1,76 +0,0 @@ -<?php - -/** - * @file - * Contains \Drupal\Tests\entity\Kernel\EntityRevisionLogTraitTest. - */ - -namespace Drupal\Tests\entity\Kernel; - -use Drupal\entity_module_test\Entity\EnhancedEntity; -use Drupal\entity_module_test\Entity\EnhancedEntityBundle; -use Drupal\KernelTests\KernelTestBase; -use Drupal\user\Entity\User; - -/** - * @coversDefaultClass \Drupal\entity\Revision\EntityRevisionLogTrait - * @group entity - */ -class EntityRevisionLogTraitTest extends KernelTestBase { - - /** - * {@inheritdoc} - */ - public static $modules = ['entity', 'entity_module_test', 'user', 'system']; - - /** - * {@inheritdoc} - */ - protected function setUp() { - parent::setUp(); - - $this->installEntitySchema('user'); - $this->installSchema('system', 'sequences'); - - $bundle = EnhancedEntityBundle::create([ - 'id' => 'default', - 'label' => 'Default', - ]); - $bundle->save(); - } - - public function testEntityRevisionLog() { - $user = User::create([ - 'name' => 'user', - ]); - $user->save(); - $user2 = User::create([ - 'name' => 'user2', - ]); - $user2->save(); - - /** @var \Drupal\entity\Revision\EntityRevisionLogInterface $entity */ - $entity = EnhancedEntity::create([ - 'type' => 'default', - 'revision_user' => $user->id(), - 'revision_created' => 1447941735, - 'revision_log_message' => 'Test message', - ]); - - $this->assertEquals(1447941735, $entity->getRevisionCreationTime()); - $this->assertEquals($user->id(), $entity->getRevisionUser()->id()); - $this->assertEquals('Test message', $entity->getRevisionLogMessage()); - - $entity->setRevisionCreationTime(1234567890); - $this->assertEquals(1234567890, $entity->getRevisionCreationTime()); - $entity->setRevisionUser($user2); - $this->assertEquals($user2->id(), $entity->getRevisionUser()->id()); - $this->assertEquals($user2->id(), $entity->getRevisionUserId()); - $entity->setRevisionUserId($user->id()); - $this->assertEquals($user->id(), $entity->getRevisionUserId()); - - $entity->setRevisionLogMessage('Giraffe!'); - $this->assertEquals('Giraffe!', $entity->getRevisionLogMessage()); - } - -} diff --git a/tests/src/Kernel/RevisionBasicUITest.php b/tests/src/Kernel/RevisionBasicUITest.php index 5cb764926b49126b012daaaf03e1fadc3bac00be..f452efc4e1efa3ea7d9e3c61676a2bb4aa15108e 100644 --- a/tests/src/Kernel/RevisionBasicUITest.php +++ b/tests/src/Kernel/RevisionBasicUITest.php @@ -33,6 +33,7 @@ class RevisionBasicUITest extends KernelTestBase { $this->installEntitySchema('user'); $this->installEntitySchema('entity_test_enhanced'); $this->installSchema('system', 'router'); + $this->installConfig(['system']); $bundle = EnhancedEntityBundle::create([ 'id' => 'default', diff --git a/tests/src/Unit/ParamConverter/EntityRevisionParamConverterTest.php b/tests/src/Unit/ParamConverter/EntityRevisionParamConverterTest.php deleted file mode 100644 index 4bf0fc542c199ab98a1df54ccf8463d632b4768d..0000000000000000000000000000000000000000 --- a/tests/src/Unit/ParamConverter/EntityRevisionParamConverterTest.php +++ /dev/null @@ -1,88 +0,0 @@ -<?php - -/** - * @file - * Contains \Drupal\Tests\entity\Unit\ParamConverter\EntityRevisionParamConverterTest. - */ - -namespace Drupal\Tests\entity\Unit\ParamConverter; - -use Drupal\Core\Entity\EntityInterface; -use Drupal\Core\Entity\EntityManagerInterface; -use Drupal\Core\Entity\EntityStorageInterface; -use Drupal\Core\Entity\EntityTypeManagerInterface; -use Drupal\entity\ParamConverter\EntityRevisionParamConverter; -use Symfony\Component\Routing\Route; - -/** - * @coversDefaultClass \Drupal\entity\ParamConverter\EntityRevisionParamConverter - * @group entity - */ -class EntityRevisionParamConverterTest extends \PHPUnit_Framework_TestCase { - - /** - * The entity manager. - * - * @var \Drupal\Core\Entity\EntityTypeManagerInterface - */ - protected $entityTypeManager; - - /** - * The tested entity revision param converter. - * - * @var \Drupal\entity\ParamConverter\EntityRevisionParamConverter - */ - protected $converter; - - /** - * {@inheritdoc} - */ - protected function setUp() { - parent::setUp(); - - $this->converter = new EntityRevisionParamConverter($this->prophesize(EntityTypeManagerInterface::class)->reveal()); - } - - protected function getTestRoute() { - $route = new Route('/test/{test_revision}'); - $route->setOption('parameters', [ - 'test_revision' => [ - 'type' => 'entity_revision:test', - ], - ]); - return $route; - } - - /** - * @covers ::applies - */ - public function testNonApplyingRoute() { - $route = new Route('/test'); - $this->assertFalse($this->converter->applies([], 'test_revision', $route)); - } - - /** - * @covers ::applies - */ - public function testApplyingRoute() { - $route = $this->getTestRoute(); - $this->assertTrue($this->converter->applies($route->getOption('parameters')['test_revision'], 'test_revision', $route)); - } - - /** - * @covers ::convert - */ - public function testConvert() { - $entity = $this->prophesize(EntityInterface::class)->reveal(); - $storage = $this->prophesize(EntityStorageInterface::class); - $storage->loadRevision(1)->willReturn($entity); - - $entity_type_manager = $this->prophesize(EntityTypeManagerInterface::class); - $entity_type_manager->getStorage('test')->willReturn($storage->reveal()); - $converter = new EntityRevisionParamConverter($entity_type_manager->reveal()); - - $route = $this->getTestRoute(); - $converter->convert(1, $route->getOption('parameters')['test_revision'], 'test_revision', ['test_revision' => 1]); - } - -} diff --git a/tests/src/Unit/RouteEnhancer/EntityRevisionRouteEnhancerTest.php b/tests/src/Unit/RouteEnhancer/EntityRevisionRouteEnhancerTest.php deleted file mode 100644 index b1ad1f8d9aab08b568506ed1ec35bedab98c474b..0000000000000000000000000000000000000000 --- a/tests/src/Unit/RouteEnhancer/EntityRevisionRouteEnhancerTest.php +++ /dev/null @@ -1,94 +0,0 @@ -<?php - -/** - * @file - * Contains \Drupal\Tests\Unit\RouteEnhancer\EntityRevisionRouteEnhancerTest. - */ - -namespace Drupal\Tests\Unit\RouteEnhancer; - -use Drupal\Core\Entity\EntityInterface; -use Drupal\entity\RouteEnhancer\EntityRevisionRouteEnhancer; -use Symfony\Cmf\Component\Routing\RouteObjectInterface; -use Symfony\Component\HttpFoundation\Request; -use Symfony\Component\Routing\Route; - -/** - * @coversDefaultClass \Drupal\entity\RouteEnhancer\EntityRevisionRouteEnhancer - * @group entity - */ -class EntityRevisionRouteEnhancerTest extends \PHPUnit_Framework_TestCase { - - /** - * @var \Drupal\entity\RouteEnhancer\EntityRevisionRouteEnhancer - */ - protected $routeEnhancer; - - /** - * {@inheritdoc} - */ - protected function setUp() { - parent::setUp(); - - $this->routeEnhancer = new EntityRevisionRouteEnhancer(); - } - - /** - * @covers ::applies - */ - public function testAppliesWithNoParameters() { - $route = new Route('/test-path'); - - $this->assertFalse($this->routeEnhancer->applies($route)); - } - - /** - * @covers ::applies - */ - public function testAppliesWithNoneRevisionParameters() { - $route = new Route('/test-path/{entity_test}', [], [], ['parameters' => ['entity_test' => ['type' => 'entity:entity_test']]]); - - $this->assertFalse($this->routeEnhancer->applies($route)); - } - - /** - * @covers ::applies - */ - public function testAppliesWithRevisionParameters() { - $route = new Route('/test-path/{entity_test_revision}', [], [], ['parameters' => ['entity_test_revision' => ['type' => 'entity_revision:entity_test']]]); - - $this->assertTrue($this->routeEnhancer->applies($route)); - } - - /** - * @covers ::enhance - */ - public function testEnhanceWithoutEntityRevision() { - $route = new Route('/test-path/{entity_test}', [], [], ['parameters' => ['entity_test' => ['type' => 'entity:entity_test']]]); - $request = Request::create('/test-path/123'); - $entity = $this->prophesize(EntityInterface::class); - - $defaults = []; - $defaults['entity_test'] = $entity->reveal(); - $defaults[RouteObjectInterface::ROUTE_OBJECT] = $route; - $this->assertEquals($defaults, $this->routeEnhancer->enhance($defaults, $request)); - } - - /** - * @covers ::enhance - */ - public function testEnhanceWithEntityRevision() { - $route = new Route('/test-path/{entity_test_revision}', [], [], ['parameters' => ['entity_test_revision' => ['type' => 'entity_revision:entity_test']]]); - $request = Request::create('/test-path/123'); - $entity = $this->prophesize(EntityInterface::class); - - $defaults = []; - $defaults['entity_test_revision'] = $entity->reveal(); - $defaults[RouteObjectInterface::ROUTE_OBJECT] = $route; - - $expected = $defaults; - $expected['_entity_revision'] = $defaults['entity_test_revision']; - $this->assertEquals($expected, $this->routeEnhancer->enhance($defaults, $request)); - } - -}