diff --git a/lib/Drupal/views/ViewListController.php b/lib/Drupal/views/ViewListController.php index 38267c7e49199544a286f1935d2e93496f428027..f71a95f2d08a7e3e5b0858b54d9e28f61d9cef14 100644 --- a/lib/Drupal/views/ViewListController.php +++ b/lib/Drupal/views/ViewListController.php @@ -7,7 +7,7 @@ namespace Drupal\views; -use Drupal\views_ui_listing\EntityListController; +use Drupal\Core\Entity\EntityListController; use Drupal\Core\Entity\EntityInterface; /** @@ -16,7 +16,7 @@ class ViewListController extends EntityListController { /** - * Overrides Drupal\views_ui_listing\EntityListController::load(); + * Overrides Drupal\Core\Entity\EntityListController::load(); */ public function load() { $entities = parent::load(); @@ -32,18 +32,18 @@ public function load() { } /** - * Overrides Drupal\views_ui_listing\EntityListController::buildRow(); + * Overrides Drupal\Core\Entity\EntityListController::buildRow(); */ public function buildRow(EntityInterface $view) { - $operations = $this->buildOperations($view); - $operations['#theme'] = 'links__ctools_dropbutton'; return array( 'data' => array( 'view_name' => theme('views_ui_view_info', array('view' => $view)), 'description' => $view->description, 'tag' => $view->tag, 'path' => implode(', ', $view->getPaths()), - 'operations' => drupal_render($operations), + 'operations' => array( + 'data' => $this->buildOperations($view), + ), ), 'title' => t('Machine name: ') . $view->id(), 'class' => array($view->isEnabled() ? 'views-ui-list-enabled' : 'views-ui-list-disabled'), @@ -51,7 +51,7 @@ public function buildRow(EntityInterface $view) { } /** - * Overrides Drupal\views_ui_listing\EntityListController::buildHeader(); + * Overrides Drupal\Core\Entity\EntityListController::buildHeader(); */ public function buildHeader() { return array( @@ -79,7 +79,7 @@ public function buildHeader() { } /** - * Implements Drupal\views_ui_listing\EntityListController::getOperations(); + * Implements Drupal\Core\Entity\EntityListController::getOperations(); */ public function getOperations(EntityInterface $view) { $uri = $view->uri(); @@ -127,11 +127,32 @@ public function getOperations(EntityInterface $view) { } /** - * Overrides Drupal\views_ui_listing\EntityListController::render(); + * Overrides Drupal\Core\Entity\EntityListController::buildOperations(); + */ + public function buildOperations(EntityInterface $entity) { + $build = parent::buildOperations($entity); + + // Allow operations to specify that they use AJAX. + foreach ($build['#links'] as &$operation) { + if (!empty($operation['ajax'])) { + $operation['attributes']['class'][] = 'use-ajax'; + } + } + + // Use theme_links__ctools_dropbutton(). + $build['#theme'] = 'links__ctools_dropbutton'; + + return $build; + } + + /** + * Overrides Drupal\Core\Entity\EntityListController::render(); */ public function render() { $list = parent::render(); $list['#attached']['css'] = ViewUI::getAdminCSS(); + $list['#attached']['library'][] = array('system', 'drupal.ajax'); + $list['#attributes']['id'] = 'views-entity-list'; return $list; } diff --git a/views_ui.info b/views_ui.info index 5a9d77245bbe34d29f28979aeb932e4a5a299305..c9eebf4192d9ce1e7078121e27b3518afc3eb1aa 100644 --- a/views_ui.info +++ b/views_ui.info @@ -4,4 +4,3 @@ package = Views core = 8.x configure = admin/structure/views dependencies[] = views -dependencies[] = views_ui_listing diff --git a/views_ui.module b/views_ui.module index f41eac54fa316ea015867c8e8a61048bcc7bc8ed..87f6fdffc44aaa4ed3650aeaa0779ff8ebdd2bd0 100644 --- a/views_ui.module +++ b/views_ui.module @@ -9,6 +9,7 @@ use Drupal\views\ViewUI; use Drupal\views\Analyzer; use Drupal\Core\Entity\EntityInterface; +use Symfony\Component\HttpFoundation\JsonResponse; /** * Implements hook_menu(). @@ -801,17 +802,19 @@ function views_ui_load($name) { * redirect back to the listing page. */ function views_ui_ajax_callback(ViewExecutable $view, $op) { - $controller = views_ui_entity_list_controller('view'); // Perform the operation. $view->storage->$op(); // If the request is via AJAX, return the rendered list as JSON. if (drupal_container()->get('request')->request->get('js')) { - return $controller->renderListAJAX(); + $list = entity_list_controller('view')->render(); + $commands = array(ajax_command_replace('#views-entity-list', drupal_render($list))); + return new JsonResponse(ajax_render($commands)); } // Otherwise, redirect back to the page. else { - drupal_goto($controller->getPath()); + $entity_info = entity_get_info('view'); + drupal_goto($entity_info['list path']); } } @@ -824,6 +827,5 @@ function views_ui_ajax_callback(ViewExecutable $view, $op) { * @see views_ui_menu() */ function views_ui_list_page() { - $controller = views_ui_entity_list_controller('view'); - return $controller->render(); + return entity_list_controller('view')->render(); } diff --git a/views_ui_listing/lib/Drupal/views_ui_listing/EntityListController.php b/views_ui_listing/lib/Drupal/views_ui_listing/EntityListController.php deleted file mode 100644 index 6f297f0c7a71758d3e1a91bdd10983c953007e97..0000000000000000000000000000000000000000 --- a/views_ui_listing/lib/Drupal/views_ui_listing/EntityListController.php +++ /dev/null @@ -1,153 +0,0 @@ -<?php - -/** - * @file - * Definition of Drupal\views_ui_listing\EntityListController. - */ - -namespace Drupal\views_ui_listing; - -use Drupal\Core\Entity\EntityInterface; - -/** - * Provides a generic implementation of an entity list controller. - */ -class EntityListController implements EntityListControllerInterface { - - /** - * The entity storage controller class. - * - * @var Drupal\Core\Entity\EntityStorageControllerInterface - */ - protected $storage; - - /** - * The entity type name. - * - * @var string - */ - protected $entityType; - - /** - * The entity info array. - * - * @var array - * - * @see entity_get_info() - */ - protected $entityInfo; - - /** - * Constructs a new EntityListController object. - * - * @param string $entity_type. - * The type of entity to be listed. - */ - public function __construct($entity_type) { - $this->entityType = $entity_type; - $this->storage = entity_get_controller($this->entityType); - $this->entityInfo = entity_get_info($this->entityType); - } - - /** - * Implements Drupal\views_ui_listing\EntityListControllerInterface::getStorageController(). - */ - public function getStorageController() { - return $this->storage; - } - - /** - * Implements Drupal\views_ui_listing\EntityListControllerInterface::load(). - */ - public function load() { - return $this->storage->load(); - } - - /** - * Implements Drupal\views_ui_listing\EntityListControllerInterface::getOperations(). - */ - public function getOperations(EntityInterface $entity) { - $uri = $entity->uri(); - $operations['edit'] = array( - 'title' => t('Edit'), - 'href' => $uri['path'] . '/edit', - 'options' => $uri['options'], - 'weight' => 10, - ); - $operations['delete'] = array( - 'title' => t('Delete'), - 'href' => $uri['path'] . '/delete', - 'options' => $uri['options'], - 'weight' => 100, - ); - return $operations; - } - - /** - * Retrieves the entity list path from the entity information. - * - * @return string - * The internal system path where the entity list will be rendered. - * - * @todo What is this method for, other than fetching the list path? Is this - * for http://drupal.org/node/1783964 ? Should it be on the interface? - */ - public function getPath() { - return $this->entityInfo['list path']; - } - - /** - * Implements Drupal\views_ui_listing\EntityListControllerInterface::buildHeader(). - */ - public function buildHeader() { - $row['label'] = t('Label'); - $row['id'] = t('Machine name'); - $row['operations'] = t('Operations'); - return $row; - } - - /** - * Implements Drupal\views_ui_listing\EntityListControllerInterface::buildRow(). - */ - public function buildRow(EntityInterface $entity) { - $row['label'] = $entity->label(); - $row['id'] = $entity->id(); - $operations = $this->buildOperations($entity); - $row['operations'] = drupal_render($operations); - return $row; - } - - /** - * Implements Drupal\views_ui_listing\EntityListControllerInterface::buildOperations(). - */ - public function buildOperations(EntityInterface $entity) { - // Retrieve and sort operations. - $operations = $this->getOperations($entity); - uasort($operations, 'drupal_sort_weight'); - $build = array( - '#theme' => 'links', - '#links' => $operations, - ); - return $build; - } - - /** - * Implements Drupal\views_ui_listing\EntityListControllerInterface::render(). - */ - public function render() { - $build = array( - '#theme' => 'table', - '#header' => $this->buildHeader(), - '#rows' => array(), - '#empty' => t('There is no @label yet. <a href="@add-url">Add one</a>.', array( - '@label' => $this->entityInfo['label'], - '@add-url' => url($this->getPath() . '/add'), - )), - ); - foreach ($this->load() as $entity) { - $build['#rows'][$entity->id()] = $this->buildRow($entity); - } - return $build; - } - -} diff --git a/views_ui_listing/lib/Drupal/views_ui_listing/EntityListControllerInterface.php b/views_ui_listing/lib/Drupal/views_ui_listing/EntityListControllerInterface.php deleted file mode 100644 index 9a80dec96c11658454325aafbd64e072992ecd1e..0000000000000000000000000000000000000000 --- a/views_ui_listing/lib/Drupal/views_ui_listing/EntityListControllerInterface.php +++ /dev/null @@ -1,83 +0,0 @@ -<?php - -/** - * @file - * Definition of Drupal\views_ui_listing\EntityListControllerInterface. - */ - -namespace Drupal\views_ui_listing; - -use Drupal\Core\Entity\EntityInterface; - -/** - * Defines an interface for entity list controllers. - */ -interface EntityListControllerInterface { - - /** - * Gets the entity storage controller. - * - * @return Drupal\Core\Entity\EntityStorageControllerInterface - * The storage controller used by this list controller. - */ - public function getStorageController(); - - /** - * Loads entities of this type from storage for listing. - * - * @return array - * An array of entities implementing Drupal\Core\Entity\EntityInterface. - */ - public function load(); - - /** - * Provides an array of information to render the operation links. - * - * @param Drupal\Core\Entity\EntityInterface $entity - * The entity the operations are for. - * - * @return array - * A array of operation link data to use in - * EntityListControllerInterface::buildOperations(). - */ - public function getOperations(EntityInterface $entity); - - /** - * Builds the header row. - * - * @return array - * An array of header strings. - */ - public function buildHeader(); - - /** - * Builds an array of data for each row. - * - * @param Drupal\Core\Entity\EntityInterface $entity - * The entity for this row of the list. - * - * @return array - * An array of fields to use for this entity. - */ - public function buildRow(EntityInterface $entity); - - /** - * Renders a list of operation links. - * - * @param Drupal\Core\Entity\EntityInterface $entity - * The entity on which the linked operations will be performed. - * - * @return array - * A renderable array of operation links. - */ - public function buildOperations(EntityInterface $entity); - - /** - * Renders the list page markup to be output. - * - * @return string - * The output markup for the listing page. - */ - public function render(); - -} diff --git a/views_ui_listing/views_ui_listing.info b/views_ui_listing/views_ui_listing.info deleted file mode 100644 index 3fb1baa9e6e0e9cd59291334418cf033a716875e..0000000000000000000000000000000000000000 --- a/views_ui_listing/views_ui_listing.info +++ /dev/null @@ -1,4 +0,0 @@ -name = Views UI Listing -description = temporary replacement for export UI. -package = Views -core = 8.x diff --git a/views_ui_listing/views_ui_listing.module b/views_ui_listing/views_ui_listing.module deleted file mode 100644 index ba58087e5bf8025a2d06171ba57f29e12840b9c5..0000000000000000000000000000000000000000 --- a/views_ui_listing/views_ui_listing.module +++ /dev/null @@ -1,22 +0,0 @@ -<?php - -/** - * Returns an entity list controller for a given entity type. - * - * @param string $entity_type - * The type of the entity. - * - * @return Drupal\Core\Entity\EntityListControllerInterface - * An entity list controller. - * - * @see hook_entity_info() - */ -function views_ui_entity_list_controller($entity_type) { - $controllers = &drupal_static(__FUNCTION__, array()); - if (!isset($instances[$entity_type])) { - $info = entity_get_info($entity_type); - $class = $info['list controller class']; - $controllers[$entity_type] = new $class($entity_type); - } - return $controllers[$entity_type]; -}