Commit a57952c6 authored by alexpott's avatar alexpott

Issue #1983844 by tim.plunkett, dawehner: Add EntityListController and convert...

Issue #1983844 by tim.plunkett, dawehner: Add EntityListController and convert picture.module callbacks to routes/controllers to provide a use-case.
parent 081af871
<?php
/**
* @file
* Contains \Drupal\Core\Entity\Controller\EntityListController.
*/
namespace Drupal\Core\Entity\Controller;
use Drupal\Core\ControllerInterface;
use Drupal\Core\Entity\EntityManager;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Defines a generic controller to list entities.
*/
class EntityListController implements ControllerInterface {
/**
* The entity manager
*
* @var \Drupal\Core\Entity\EntityManager
*/
protected $entityManager;
/**
* Creates an EntityListController object.
*
* @param \Drupal\Core\Entity\EntityManager $entity_manager
* The entity manager.
*/
public function __construct(EntityManager $entity_manager) {
$this->entityManager = $entity_manager;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static(
$container->get('plugin.manager.entity')
);
}
/**
* Provides the listing page for any entity type.
*
* @return array
* A render array as expected by drupal_render().
*/
public function listing($entity_type) {
return $this->entityManager->getListController($entity_type)->render();
}
}
......@@ -28,8 +28,7 @@ function config_test_uri(ConfigTest $config_test) {
function config_test_menu() {
$items['admin/structure/config_test'] = array(
'title' => 'Test configuration',
'page callback' => 'config_test_list_page',
'access callback' => TRUE,
'route_name' => 'config_test_list_page',
);
$items['admin/structure/config_test/add'] = array(
'title' => 'Add test configuration',
......@@ -79,15 +78,6 @@ function config_test_load($id) {
return entity_load('config_test', $id);
}
/**
* Page callback; Lists available ConfigTest objects.
*/
function config_test_list_page() {
return Drupal::entityManager()
->getListController('config_test')
->render();
}
/**
* Page callback: Presents the ConfigTest creation form.
*
......
config_test_list_page:
pattern: '/admin/structure/config_test'
defaults:
_content: '\Drupal\Core\Entity\Controller\EntityListController::listing'
entity_type: 'config_test'
requirements:
_access: 'TRUE'
......@@ -28,6 +28,14 @@ class PictureMappingFormController extends EntityFormController {
* The array containing the complete form.
*/
public function form(array $form, array &$form_state) {
if ($this->operation == 'duplicate') {
drupal_set_title(t('<em>Duplicate picture mapping</em> @label', array('@label' => $this->entity->label())), PASS_THROUGH);
$this->entity = $this->entity->createDuplicate();
}
if ($this->operation == 'edit') {
drupal_set_title(t('<em>Edit picture mapping</em> @label', array('@label' => $this->entity->label())), PASS_THROUGH);
}
$picture_mapping = $this->entity;
$form['label'] = array(
'#type' => 'textfield',
......
......@@ -23,7 +23,7 @@
* "storage" = "Drupal\Core\Config\Entity\ConfigStorageController",
* "list" = "Drupal\picture\PictureMappingListController",
* "form" = {
* "default" = "Drupal\picture\PictureMappingFormController",
* "edit" = "Drupal\picture\PictureMappingFormController",
* "add" = "Drupal\picture\PictureMappingFormController",
* "duplicate" = "Drupal\picture\PictureMappingFormController"
* }
......
......@@ -56,34 +56,21 @@ function picture_menu() {
$items['admin/config/media/picturemapping'] = array(
'title' => 'Picture Mappings',
'description' => 'Manage picture mappings',
'access arguments' => array('administer pictures'),
'weight' => 10,
'page callback' => 'picture_mapping_page',
'file' => 'picture_mapping.admin.inc',
'route_name' => 'picture_mapping_page',
);
$items['admin/config/media/picturemapping/add'] = array(
'title' => 'Add picture mapping',
'page callback' => 'picture_mapping_page_add',
'access callback' => 'user_access',
'access arguments' => array('administer pictures'),
'route_name' => 'picture_mapping_page_add',
'type' => MENU_LOCAL_ACTION,
'file' => 'picture_mapping.admin.inc',
);
$items['admin/config/media/picturemapping/%picture_mapping/edit'] = array(
'title' => 'Edit picture mapping',
'page callback' => 'picture_mapping_page_edit',
'page arguments' => array(4),
'access callback' => 'user_access',
'access arguments' => array('administer pictures'),
'file' => 'picture_mapping.admin.inc',
'route_name' => 'picture_mapping_page_edit',
);
$items['admin/config/media/picturemapping/%picture_mapping/duplicate'] = array(
'title' => 'Duplicate picture mapping',
'page callback' => 'picture_mapping_page_duplicate',
'page arguments' => array(4),
'access callback' => 'user_access',
'access arguments' => array('administer pictures'),
'file' => 'picture_mapping.admin.inc',
'route_name' => 'picture_mapping_page_duplicate',
);
$items['admin/config/media/picturemapping/%picture_mapping/delete'] = array(
'title' => 'Delete',
......
picture_mapping_page:
pattern: '/admin/config/media/picturemapping'
defaults:
_content: '\Drupal\Core\Entity\Controller\EntityListController::listing'
entity_type: 'picture_mapping'
requirements:
_permission: 'administer pictures'
picture_mapping_page_add:
pattern: '/admin/config/media/picturemapping/add'
defaults:
_entity_form: 'picture_mapping.add'
requirements:
_permission: 'administer pictures'
picture_mapping_page_edit:
pattern: '/admin/config/media/picturemapping/{picture_mapping}/edit'
defaults:
_entity_form: 'picture_mapping.edit'
requirements:
_permission: 'administer pictures'
picture_mapping_page_duplicate:
pattern: '/admin/config/media/picturemapping/{picture_mapping}/duplicate'
defaults:
_entity_form: 'picture_mapping.duplicate'
requirements:
_permission: 'administer pictures'
picture_mapping_action_confirm:
pattern: '/admin/config/media/picturemapping/{picture_mapping}/delete'
defaults:
......
<?php
/**
* @file
* Administration functions to maintain picture mappings.
*/
use \Drupal\picture\PictureMapping;
/**
* Page callback: Presents the picture list page.
*
* @return
* A render array for a page containing a list of content.
*
* @see picture_menu()
*/
function picture_mapping_page() {
return Drupal::entityManager()
->getListController('picture_mapping')
->render();
}
/**
* Page callback: Presents the picture mapping editing form.
*
* @param Drupal\picture\PictureMapping $picture_mapping
*
* @return
* A render array for a page containing a list of content.
*
* @see picture_menu()
*/
function picture_mapping_page_edit($picture_mapping) {
drupal_set_title(t('<em>Edit picture mapping</em> @label', array('@label' => $picture_mapping->label())), PASS_THROUGH);
return entity_get_form($picture_mapping);
}
/**
* Page callback: Presents the picture mapping duplicate form.
*
* @param Drupal\picture\PictureMapping $picture_mapping
*
* @return
* A render array for a page containing a list of content.
*
* @see picture_menu()
*/
function picture_mapping_page_duplicate($picture_mapping) {
drupal_set_title(t('<em>Duplicate picture mapping</em> @label', array('@label' => $picture_mapping->label())), PASS_THROUGH);
return entity_get_form($picture_mapping->createDuplicate());
}
/**
* Page callback: Provides the new picture mapping addition form.
*
* @return
* A render array for a page containing a list of content.
*
* @see picture_menu()
*/
function picture_mapping_page_add() {
$picture_mapping = entity_create('picture_mapping', array());
$form = entity_get_form($picture_mapping);
return $form;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment