diff --git a/core/lib/Drupal/Core/Entity/EntityAutocomplete.php b/core/lib/Drupal/Core/Entity/EntityAutocomplete.php index 20ce025..30647bb 100644 --- a/core/lib/Drupal/Core/Entity/EntityAutocomplete.php +++ b/core/lib/Drupal/Core/Entity/EntityAutocomplete.php @@ -9,6 +9,9 @@ use Drupal\Core\Entity\Query\QueryFactory; +/** + * Provides a generic autocompletion service, + */ class EntityAutocomplete { /** @@ -66,7 +69,7 @@ public function getMatches($string, $entity_type_id) { foreach ($entities as $entity) { /** @var \Drupal\Core\Entity\EntityInterface $entity */ if ($entity->access('view')) { - $matches[] = array('value' => $entity->uuid(), 'label' => $entity->label()); + $matches[] = ['value' => $entity->uuid(), 'label' => $entity->label()]; } } } diff --git a/core/modules/system/src/Controller/EntityAutocompleteController.php b/core/modules/system/src/Controller/EntityAutocompleteController.php index e34a480..856d332 100644 --- a/core/modules/system/src/Controller/EntityAutocompleteController.php +++ b/core/modules/system/src/Controller/EntityAutocompleteController.php @@ -13,6 +13,12 @@ use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\HttpFoundation\Request; +/** + * Defines a controller for generic entity autocompletion. + * + * In contrast to the one from entity reference, this one does not depend on + * fields at all. + */ class EntityAutocompleteController extends ControllerBase { /** diff --git a/core/modules/views/config/schema/views.area.schema.yml b/core/modules/views/config/schema/views.area.schema.yml index b75deb1..69b4726 100644 --- a/core/modules/views/config/schema/views.area.schema.yml +++ b/core/modules/views/config/schema/views.area.schema.yml @@ -8,7 +8,7 @@ views.area.entity: type: views_area label: 'Entity' mapping: - entity_id: + entity_id_uuid: type: string label: 'ID' view_mode: diff --git a/core/modules/views/src/Plugin/views/area/Entity.php b/core/modules/views/src/Plugin/views/area/Entity.php index baecae0..87097e2 100644 --- a/core/modules/views/src/Plugin/views/area/Entity.php +++ b/core/modules/views/src/Plugin/views/area/Entity.php @@ -7,10 +7,8 @@ namespace Drupal\views\Plugin\views\area; -use Drupal\Core\Entity\EntityManager; use Drupal\Core\Entity\EntityManagerInterface; use Drupal\Core\Form\FormStateInterface; -use Drupal\Core\Plugin\ContainerFactoryPluginInterface; use Drupal\views\Plugin\views\display\DisplayPluginBase; use Drupal\views\ViewExecutable; use Symfony\Component\DependencyInjection\ContainerInterface; @@ -80,9 +78,9 @@ protected function defineOptions() { $options['tokenize']['default'] = TRUE; // Contains either the entity ID or the UUID. - $options['entity_id_uuid'] = array('default' => ''); - $options['view_mode'] = array('default' => 'default'); - $options['bypass_access'] = array('default' => FALSE); + $options['entity_id_uuid'] = ['default' => '']; + $options['view_mode'] = ['default' => 'default']; + $options['bypass_access'] = ['default' => FALSE]; return $options; } @@ -100,14 +98,14 @@ public function buildOptionsForm(&$form, FormStateInterface $form_state) { '#default_value' => $this->options['view_mode'], ); - $form['entity_id_uuid'] = array( + $form['entity_id_uuid'] = [ '#title' => $this->t('ID / UUID'), '#description' => $this->t('You can put in either the entity ID or the UUID'), '#type' => 'textfield', '#default_value' => $this->options['entity_id_uuid'], '#autocomplete_route_name' => 'system.entity_autocomplete', '#autocomplete_route_parameters' => ['entity_type' => $this->entityType], - ); + ]; $form['bypass_access'] = array( '#type' => 'checkbox', @@ -124,7 +122,7 @@ public function submitOptionsForm(&$form, FormStateInterface $form_state, &$opti parent::submitOptionsForm($form, $form_state); if ($entity = $this->entityManager->getStorage($this->entityType)->load($options['entity_id_uuid'])) { - $options['entity_id_uuid']['uuid'] = $entity->uuid(); + $options['entity_id_uuid'] = $entity->uuid(); } } @@ -145,7 +143,7 @@ public function render($empty = FALSE) { } } - return array(); + return []; } } diff --git a/core/modules/views/src/Tests/Handler/AreaEntityTest.php b/core/modules/views/src/Tests/Handler/AreaEntityTest.php index 19da572..f68c8f0 100644 --- a/core/modules/views/src/Tests/Handler/AreaEntityTest.php +++ b/core/modules/views/src/Tests/Handler/AreaEntityTest.php @@ -9,7 +9,6 @@ use Drupal\Core\Entity\EntityTypeInterface; use Drupal\Core\Form\FormState; -use Drupal\views\Entity\View; use Drupal\views\Tests\ViewTestBase; use Drupal\views\Views; @@ -86,8 +85,8 @@ public function testEntityArea() { } $view = Views::getView('test_entity_area'); - $preview = $view->preview('default', array($entities[1]->id())); - $this->drupalSetContent(drupal_render($preview)); + $preview = $view->preview('default', [$entities[1]->id()]); + $this->setRawContent(\Drupal::service('renderer')->render($preview)); $result = $this->xpath('//div[@class = "view-header"]'); $this->assertTrue(strpos(trim((string) $result[0]), $entities[0]->label()) !== FALSE, 'The rendered entity appears in the header of the view.');