Issue #2029321 by tim.plunkett, aspilicious, swentel: Provide list and form controllers for EntityViewMode and EntityFormMode.

8.0.x
Alex Pott 2013-07-14 15:37:55 -04:00
parent d03acd3ce9
commit 9cd28855d3
21 changed files with 995 additions and 24 deletions

View File

@ -10,6 +10,102 @@
use Drupal\Core\Config\Entity\ConfigStorageController; use Drupal\Core\Config\Entity\ConfigStorageController;
/**
* Implements hook_permission().
*/
function entity_permission() {
return array(
'administer display modes' => array(
'title' => t('Add, edit, and delete custom display modes.'),
),
);
}
/**
* Implements hook_menu().
*/
function entity_menu() {
$items = array();
$items['admin/structure/display-modes'] = array(
'title' => 'Display modes',
'description' => 'Configure what displays are available for your content and forms.',
'page callback' => 'system_admin_menu_block_page',
'access arguments' => array('administer display modes'),
'file' => 'system.admin.inc',
'file path' => drupal_get_path('module', 'system'),
);
// View modes.
$items['admin/structure/display-modes/view'] = array(
'title' => 'View modes',
'description' => 'Manage custom view modes.',
'route_name' => 'entity_view_mode.list',
);
$items['admin/structure/display-modes/view/list'] = array(
'title' => 'List',
'type' => MENU_DEFAULT_LOCAL_TASK,
);
$items['admin/structure/display-modes/view/add'] = array(
'title' => 'Add view mode',
'route_name' => 'entity_view_mode.add',
'type' => MENU_SIBLING_LOCAL_TASK,
);
$items['admin/structure/display-modes/view/add/%'] = array(
'route_name' => 'entity_view_mode.add_type',
);
$items['admin/structure/display-modes/view/manage/%'] = array(
'title' => 'Edit view mode',
'route_name' => 'entity_view_mode.edit',
);
$items['admin/structure/display-modes/view/manage/%/delete'] = array(
'route_name' => 'entity_view_mode.delete',
);
// Form modes.
$items['admin/structure/display-modes/form'] = array(
'title' => 'Form modes',
'description' => 'Manage custom form modes.',
'route_name' => 'entity_form_mode.list',
);
$items['admin/structure/display-modes/form/list'] = array(
'title' => 'List',
'type' => MENU_DEFAULT_LOCAL_TASK,
);
$items['admin/structure/display-modes/form/add'] = array(
'title' => 'Add form mode',
'route_name' => 'entity_form_mode.add',
'type' => MENU_SIBLING_LOCAL_TASK,
);
$items['admin/structure/display-modes/form/add/%'] = array(
'route_name' => 'entity_form_mode.add_type',
);
$items['admin/structure/display-modes/form/manage/%'] = array(
'title' => 'Edit form mode',
'route_name' => 'entity_form_mode.edit',
);
$items['admin/structure/display-modes/form/manage/%/delete'] = array(
'route_name' => 'entity_form_mode.delete',
);
return $items;
}
/**
* Implements hook_local_actions().
*/
function entity_local_actions() {
return array(
array(
'route_name' => 'entity_view_mode.add',
'title' => t('Add view mode'),
'appears_on' => array(
'entity_view_mode.list',
),
),
);
}
/** /**
* Implements hook_entity_bundle_rename(). * Implements hook_entity_bundle_rename().
*/ */

View File

@ -0,0 +1,69 @@
entity_view_mode.list:
pattern: '/admin/structure/display-modes/view'
defaults:
_entity_list: 'view_mode'
requirements:
_permission: 'administer display modes'
entity_view_mode.add:
pattern: '/admin/structure/display-modes/view/add'
defaults:
_content: '\Drupal\entity\Controller\EntityDisplayModeController::viewModeTypeSelection'
requirements:
_permission: 'administer display modes'
entity_view_mode.add_type:
pattern: '/admin/structure/display-modes/view/add/{entity_type}'
defaults:
_entity_form: 'view_mode.add'
requirements:
_permission: 'administer display modes'
entity_view_mode.edit:
pattern: '/admin/structure/display-modes/view/manage/{view_mode}'
defaults:
_entity_form: 'view_mode.edit'
requirements:
_entity_access: 'view_mode.update'
entity_view_mode.delete:
pattern: '/admin/structure/display-modes/view/manage/{view_mode}/delete'
defaults:
_entity_form: 'view_mode.delete'
requirements:
_entity_access: 'view_mode.delete'
entity_form_mode.list:
pattern: '/admin/structure/display-modes/form'
defaults:
_entity_list: 'form_mode'
requirements:
_permission: 'administer display modes'
entity_form_mode.add:
pattern: '/admin/structure/display-modes/form/add'
defaults:
_content: '\Drupal\entity\Controller\EntityDisplayModeController::formModeTypeSelection'
requirements:
_permission: 'administer display modes'
entity_form_mode.add_type:
pattern: '/admin/structure/display-modes/form/add/{entity_type}'
defaults:
_entity_form: 'form_mode.add'
requirements:
_permission: 'administer display modes'
entity_form_mode.edit:
pattern: '/admin/structure/display-modes/form/manage/{form_mode}'
defaults:
_entity_form: 'form_mode.edit'
requirements:
_entity_access: 'form_mode.update'
entity_form_mode.delete:
pattern: '/admin/structure/display-modes/form/manage/{form_mode}/delete'
defaults:
_entity_form: 'form_mode.delete'
requirements:
_entity_access: 'form_mode.delete'

View File

@ -0,0 +1,93 @@
<?php
/**
* @file
* Contains \Drupal\entity\Controller\EntityDisplayModeController.
*/
namespace Drupal\entity\Controller;
use Drupal\Component\Plugin\PluginManagerInterface;
use Drupal\Core\Controller\ControllerInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Provides methods for entity display mode routes.
*/
class EntityDisplayModeController implements ControllerInterface {
/**
* The entity manager.
*
* @var \Drupal\Component\Plugin\PluginManagerInterface
*/
protected $entityManager;
/**
* Constructs a new EntityDisplayModeFormBase.
*
* @param \Drupal\Component\Plugin\PluginManagerInterface $entity_manager
* The entity manager.
*/
public function __construct(PluginManagerInterface $entity_manager) {
$this->entityManager = $entity_manager;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static(
$container->get('plugin.manager.entity')
);
}
/**
* Provides a list of eligible entity types for adding view modes.
*
* @return array
* A list of entity types to add a view mode for.
*/
public function viewModeTypeSelection() {
drupal_set_title(t('Choose view mode entity type'));
$entity_types = array();
foreach ($this->entityManager->getDefinitions() as $entity_type => $entity_info) {
if ($entity_info['fieldable'] && isset($entity_info['controllers']['render'])) {
$entity_types[$entity_type] = array(
'title' => $entity_info['label'],
'href' => 'admin/structure/display-modes/view/add/' . $entity_type,
'localized_options' => array(),
);
}
}
return array(
'#theme' => 'admin_block_content',
'#content' => $entity_types,
);
}
/**
* Provides a list of eligible entity types for adding form modes.
*
* @return array
* A list of entity types to add a form mode for.
*/
public function formModeTypeSelection() {
drupal_set_title(t('Choose form mode entity type'));
$entity_types = array();
foreach ($this->entityManager->getDefinitions() as $entity_type => $entity_info) {
if ($entity_info['fieldable'] && isset($entity_info['controllers']['form'])) {
$entity_types[$entity_type] = array(
'title' => $entity_info['label'],
'href' => 'admin/structure/display-modes/form/add/' . $entity_type,
'localized_options' => array(),
);
}
}
return array(
'#theme' => 'admin_block_content',
'#content' => $entity_types,
);
}
}

View File

@ -0,0 +1,31 @@
<?php
/**
* @file
* Contains \Drupal\entity\EntityDisplayModeAccessController.
*/
namespace Drupal\entity;
use Drupal\Core\Entity\EntityAccessController;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Session\AccountInterface;
/**
* Provides the access controller for entity display modes.
*/
class EntityDisplayModeAccessController extends EntityAccessController {
/**
* {@inheritdoc}
*/
protected function checkAccess(EntityInterface $entity, $operation, $langcode, AccountInterface $account) {
if ($operation === 'view') {
return TRUE;
}
elseif (in_array($operation, array('create', 'update', 'delete'))) {
return user_access('administer display modes', $account);
}
}
}

View File

@ -12,7 +12,7 @@ use Drupal\Core\Config\Entity\ConfigEntityBase;
/** /**
* Base class for config entity types that hold settings for form and view modes. * Base class for config entity types that hold settings for form and view modes.
*/ */
abstract class EntityDisplayModeBase extends ConfigEntityBase { abstract class EntityDisplayModeBase extends ConfigEntityBase implements EntityDisplayModeInterface {
/** /**
* The ID of the form or view mode. * The ID of the form or view mode.
@ -38,8 +38,8 @@ abstract class EntityDisplayModeBase extends ConfigEntityBase {
/** /**
* The entity type this form or view mode is used for. * The entity type this form or view mode is used for.
* *
* This is not to be confused with EntityViewMode::entityType which is * This is not to be confused with EntityDisplayModeBase::$entityType which is
* inherited from Entity::entityType. * inherited from Entity::$entityType.
* *
* @var string * @var string
*/ */
@ -55,6 +55,24 @@ abstract class EntityDisplayModeBase extends ConfigEntityBase {
* *
* @var bool * @var bool
*/ */
public $status = FALSE; public $status = TRUE;
/**
* {@inheritdoc}
*/
public static function sort($a, $b) {
// Sort by the type of entity the view mode is used for.
$a_type = $a->getTargetType();
$b_type = $b->getTargetType();
$type_order = strnatcasecmp($a_type, $b_type);
return $type_order != 0 ? $type_order : parent::sort($a, $b);
}
/**
* {@inheritdoc}
*/
public function getTargetType() {
return $this->targetEntityType;
}
} }

View File

@ -0,0 +1,25 @@
<?php
/**
* @file
* Contains \Drupal\entity\EntityDisplayModeInterface.
*/
namespace Drupal\entity;
use Drupal\Core\Config\Entity\ConfigEntityInterface;
/**
* Provides an interface for entity types that hold form and view mode settings.
*/
interface EntityDisplayModeInterface extends ConfigEntityInterface {
/**
* Returns the entity type this display mode is used for.
*
* @return string
* The entity type name.
*/
public function getTargetType();
}

View File

@ -0,0 +1,155 @@
<?php
/**
* @file
* Contains \Drupal\entity\EntityDisplayModeListController.
*/
namespace Drupal\entity;
use Drupal\Component\Utility\String;
use Drupal\Core\Config\Entity\ConfigEntityListController;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Entity\EntityStorageControllerInterface;
use Drupal\Core\Extension\ModuleHandlerInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Provides the listing for entity display modes.
*/
class EntityDisplayModeListController extends ConfigEntityListController {
/**
* The entity info for all entity types.
*
* @var array
*/
protected $entityInfoComplete;
/**
* Constructs a new EntityListController object.
*
* @param string $entity_type
* The type of entity to be listed.
* @param array $entity_info
* An array of entity info for the entity type.
* @param \Drupal\Core\Entity\EntityStorageControllerInterface $storage
* The entity storage controller class.
* @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
* The module handler to invoke hooks on.
* @param array $entity_info_complete
* The entity info for all entity types.
*/
public function __construct($entity_type, array $entity_info, EntityStorageControllerInterface $storage, ModuleHandlerInterface $module_handler, array $entity_info_complete) {
parent::__construct($entity_type, $entity_info, $storage, $module_handler);
$this->entityInfoComplete = $entity_info_complete;
}
/**
* {@inheritdoc}
*/
public static function createInstance(ContainerInterface $container, $entity_type, array $entity_info) {
$entity_manager = $container->get('plugin.manager.entity');
return new static(
$entity_type,
$entity_info,
$entity_manager->getStorageController($entity_type),
$container->get('module_handler'),
$entity_manager->getDefinitions()
);
}
/**
* {@inheritdoc}
*/
public function buildHeader() {
$header = parent::buildHeader();
unset($header['id']);
return $header;
}
/**
* {@inheritdoc}
*/
public function buildRow(EntityInterface $entity) {
$row = parent::buildRow($entity);
unset($row['id']);
return $row;
}
/**
* {@inheritdoc}
*/
public function load() {
$entities = array();
foreach (parent::load() as $entity) {
$entities[$entity->getTargetType()][] = $entity;
}
return $entities;
}
/**
* {@inheritdoc}
*/
public function render() {
$build = array();
foreach ($this->load() as $entity_type => $entities) {
if (!isset($this->entityInfoComplete[$entity_type])) {
continue;
}
// Filter entities
if ($this->entityInfoComplete[$entity_type]['fieldable'] && !$this->isValidEntity($entity_type)) {
continue;
}
$table = array(
'#prefix' => '<h2>' . $this->entityInfoComplete[$entity_type]['label'] . '</h2>',
'#type' => 'table',
'#header' => $this->buildHeader(),
'#rows' => array(),
);
foreach ($entities as $entity) {
if ($row = $this->buildRow($entity)) {
$table['#rows'][$entity->id()] = $row;
}
}
// Move content at the top.
if ($entity_type == 'node') {
$table['#weight'] = -10;
}
$short_type = str_replace('_mode', '', $this->entityType);
$table['#rows']['_add_new'][] = array(
'data' => array(
'#type' => 'link',
'#href' => "admin/structure/display-modes/$short_type/add/$entity_type",
'#title' => t('Add new %label @entity-type', array('%label' => $this->entityInfoComplete[$entity_type]['label'], '@entity-type' => strtolower($this->entityInfo['label']))),
'#options' => array(
'html' => TRUE,
),
),
'colspan' => count($table['#header']),
);
$build[$entity_type] = $table;
}
return $build;
}
/**
* Filters entities based on their controllers.
*
* @param $entity_type
* The entity type of the entity that needs to be validated.
*
* @return bool
* TRUE if the entity has the correct controller, FALSE if the entity
* doesn't has the correct controller.
*/
protected function isValidEntity($entity_type) {
return isset($this->entityInfoComplete[$entity_type]['controllers']['render']);
}
}

View File

@ -7,11 +7,9 @@
namespace Drupal\entity; namespace Drupal\entity;
use Drupal\Core\Config\Entity\ConfigEntityInterface;
/** /**
* Provides an interface defining an entity form mode entity type. * Provides an interface defining an entity form mode entity type.
*/ */
interface EntityFormModeInterface extends ConfigEntityInterface { interface EntityFormModeInterface extends EntityDisplayModeInterface {
} }

View File

@ -0,0 +1,29 @@
<?php
/**
* @file
* Contains \Drupal\entity\EntityFormModeListController.
*/
namespace Drupal\entity;
/**
* Provides the listing for entity display modes.
*/
class EntityFormModeListController extends EntityDisplayModeListController {
/**
* Filters entities based on their controllers.
*
* @param $entity_type
* The entity type of the entity that needs to be validated.
*
* @return bool
* TRUE if the entity has the correct controller, FALSE if the entity
* doesn't has the correct controller.
*/
protected function isValidEntity($entity_type) {
return isset($this->entityInfoComplete[$entity_type]['controllers']['form']);
}
}

View File

@ -7,11 +7,9 @@
namespace Drupal\entity; namespace Drupal\entity;
use Drupal\Core\Config\Entity\ConfigEntityInterface;
/** /**
* Provides an interface defining an entity view mode entity type. * Provides an interface defining an entity view mode entity type.
*/ */
interface EntityViewModeInterface extends ConfigEntityInterface { interface EntityViewModeInterface extends EntityDisplayModeInterface {
} }

View File

@ -0,0 +1,93 @@
<?php
/**
* @file
* Contains \Drupal\entity\Form\EntityDisplayModeAddForm.
*/
namespace Drupal\entity\Form;
use Drupal\Component\Plugin\PluginManagerInterface;
use Drupal\Core\Entity\Query\QueryFactory;
use Drupal\Core\Extension\ModuleHandlerInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
/**
* Provides the add form for entity display modes.
*/
class EntityDisplayModeAddForm extends EntityDisplayModeFormBase {
/**
* @var string
*/
protected $entityType;
/**
* The entity manager.
*
* @var \Drupal\Component\Plugin\PluginManagerInterface
*/
protected $entityManager;
/**
* Constructs a new EntityDisplayModeAddForm.
*
* @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
* The module handler.
* @param \Drupal\Core\Entity\Query\QueryFactory $query_factory
* The entity query factory.
* @param array $entity_info
* The entity type definition.
* @param \Drupal\Component\Plugin\PluginManagerInterface $entity_manager
* The entity manager.
*/
public function __construct(ModuleHandlerInterface $module_handler, QueryFactory $query_factory, array $entity_info, PluginManagerInterface $entity_manager) {
parent::__construct($module_handler, $query_factory, $entity_info);
$this->entityManager = $entity_manager;
}
/**
* {@inheritdoc}
*/
public static function createInstance(ContainerInterface $container, $entity_type, array $entity_info) {
return new static(
$container->get('module_handler'),
$container->get('entity.query'),
$entity_info,
$container->get('plugin.manager.entity')
);
}
/**
* {@inheritdoc}
*/
public function buildForm(array $form, array &$form_state, $entity_type = NULL) {
$this->entityType = $entity_type;
return parent::buildForm($form, $form_state);
}
/**
* {@inheritdoc}
*/
public function validate(array $form, array &$form_state) {
parent::validate($form, $form_state);
form_set_value($form['id'], $this->entityType . '.' . $form_state['values']['id'], $form_state);
}
/**
* {@inheritdoc}
*/
protected function prepareEntity() {
$definition = $this->entityManager->getDefinition($this->entityType);
if (!$definition['fieldable'] || !isset($definition['controllers']['render'])) {
throw new NotFoundHttpException();
}
drupal_set_title(t('Add new %label @entity-type', array('%label' => $definition['label'], '@entity-type' => strtolower($this->entityInfo['label']))), PASS_THROUGH);
$this->entity->targetEntityType = $this->entityType;
}
}

View File

@ -0,0 +1,62 @@
<?php
/**
* @file
* Contains \Drupal\entity\Form\EntityDisplayModeDeleteForm.
*/
namespace Drupal\entity\Form;
use Drupal\Core\Entity\EntityConfirmFormBase;
/**
* Provides the delete form for entity display modes.
*/
class EntityDisplayModeDeleteForm extends EntityConfirmFormBase {
/**
* {@inheritdoc}
*/
public function getCancelPath() {
$short_type = str_replace('_mode', '', $this->entity->entityType());
return "admin/structure/display-modes/$short_type";
}
/**
* {@inheritdoc}
*/
public function getQuestion() {
$entity_info = $this->entity->entityInfo();
return t('Are you sure you want to delete the %label @entity-type?', array('%label' => $this->entity->label(), '@entity-type' => strtolower($entity_info['label'])));
}
/**
* {@inheritdoc}
*/
public function getDescription() {
$entity_info = $this->entity->entityInfo();
return t('Deleting a @entity-type will cause any output still requesting to use that @entity-type to use the default display settings.', array('@entity-type' => strtolower($entity_info['label'])));
}
/**
* {@inheritdoc}
*/
public function getConfirmText() {
return t('Delete');
}
/**
* {@inheritdoc}
*/
public function submit(array $form, array &$form_state) {
parent::submit($form, $form_state);
$entity_info = $this->entity->entityInfo();
drupal_set_message(t('Deleted the %label @entity-type.', array('%label' => $this->entity->label(), '@entity-type' => strtolower($entity_info['label']))));
$this->entity->delete();
entity_info_cache_clear();
$short_type = str_replace('_mode', '', $this->entity->entityType());
$form_state['redirect'] = "admin/structure/display-modes/$short_type";
}
}

View File

@ -0,0 +1,23 @@
<?php
/**
* @file
* Contains \Drupal\entity\Form\EntityDisplayModeEditForm.
*/
namespace Drupal\entity\Form;
/**
* Provides the edit form for entity display modes.
*/
class EntityDisplayModeEditForm extends EntityDisplayModeFormBase {
/**
* {@inheritdoc}
*/
public function delete(array $form, array &$form_state) {
$short_type = str_replace('_mode', '', $this->entity->entityType());
$form_state['redirect'] = "admin/structure/display-modes/$short_type/manage/" . $this->entity->id() . '/delete';
}
}

View File

@ -0,0 +1,121 @@
<?php
/**
* @file
* Contains \Drupal\entity\Form\EntityDisplayModeFormBase.
*/
namespace Drupal\entity\Form;
use Drupal\Core\Entity\EntityControllerInterface;
use Drupal\Core\Entity\EntityFormController;
use Drupal\Core\Entity\Query\QueryFactory;
use Drupal\Core\Extension\ModuleHandlerInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Provides the generic base class for entity display mode forms.
*/
abstract class EntityDisplayModeFormBase extends EntityFormController implements EntityControllerInterface {
/**
* The entity query factory.
*
* @var \Drupal\Core\Entity\Query\QueryFactory
*/
protected $queryFactory;
/**
* The entity type definition.
*
* @var array
*/
protected $entityInfo;
/**
* Constructs a new EntityDisplayModeFormBase.
*
* @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
* The module handler.
* @param \Drupal\Core\Entity\Query\QueryFactory $query_factory
* The entity query factory.
* @param array $entity_info
* The entity type definition.
*/
public function __construct(ModuleHandlerInterface $module_handler, QueryFactory $query_factory, array $entity_info) {
parent::__construct($module_handler);
$this->queryFactory = $query_factory;
$this->entityInfo = $entity_info;
}
/**
* {@inheritdoc}
*/
public static function createInstance(ContainerInterface $container, $entity_type, array $entity_info) {
return new static(
$container->get('module_handler'),
$container->get('entity.query'),
$entity_info
);
}
/**
* {@inheritdoc}
*/
public function form(array $form, array &$form_state) {
$form['label'] = array(
'#type' => 'textfield',
'#title' => t('Label'),
'#maxlength' => 100,
'#default_value' => $this->entity->label(),
);
$form['id'] = array(
'#type' => 'machine_name',
'#title' => t('Machine-readable name'),
'#description' => t('A unique machine-readable name. Can only contain lowercase letters, numbers, and underscores.'),
'#disabled' => !$this->entity->isNew(),
'#default_value' => $this->entity->id(),
'#field_prefix' => $this->entity->isNew() ? $this->entity->getTargetType() . '.' : '',
'#machine_name' => array(
'exists' => array($this, 'exists'),
'replace_pattern' => '[^a-z0-9_.]+',
),
);
return $form;
}
/**
* Determines if the display mode already exists.
*
* @param string|int $entity_id
* The entity ID.
* @param array $element
* The form element.
* @param array $form_state
* The form state.
*
* @return bool
* TRUE if the display mode exists, FALSE otherwise.
*/
public function exists($entity_id, array $element, array $form_state) {
return (bool) $this->queryFactory
->get($this->entity->entityType())
->condition('id', $element['#field_prefix'] . $entity_id)
->execute();
}
/**
* {@inheritdoc}
*/
public function save(array $form, array &$form_state) {
drupal_set_message(t('Saved the %label @entity-type.', array('%label' => $this->entity->label(), '@entity-type' => strtolower($this->entityInfo['label']))));
$this->entity->save();
entity_info_cache_clear();
$short_type = str_replace('_mode', '', $this->entity->entityType());
$form_state['redirect'] = "admin/structure/display-modes/$short_type";
}
}

View File

@ -0,0 +1,30 @@
<?php
/**
* @file
* Contains \Drupal\entity\Form\EntityFormModeAddForm.
*/
namespace Drupal\entity\Form;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
/**
* Provides the add form for entity display modes.
*/
class EntityFormModeAddForm extends EntityDisplayModeAddForm {
/**
* {@inheritdoc}
*/
protected function prepareEntity() {
$definition = $this->entityManager->getDefinition($this->entityType);
if (!$definition['fieldable'] || !isset($definition['controllers']['form'])) {
throw new NotFoundHttpException();
}
drupal_set_title(t('Add new %label @entity-type', array('%label' => $definition['label'], '@entity-type' => strtolower($this->entityInfo['label']))), PASS_THROUGH);
$this->entity->targetEntityType = $this->entityType;
}
}

View File

@ -34,6 +34,13 @@ use Drupal\entity\EntityFormModeInterface;
* label = @Translation("Form mode"), * label = @Translation("Form mode"),
* module = "entity", * module = "entity",
* controllers = { * controllers = {
* "list" = "Drupal\entity\EntityFormModeListController",
* "access" = "Drupal\entity\EntityDisplayModeAccessController",
* "form" = {
* "add" = "Drupal\entity\Form\EntityFormModeAddForm",
* "edit" = "Drupal\entity\Form\EntityDisplayModeEditForm",
* "delete" = "Drupal\entity\Form\EntityDisplayModeDeleteForm"
* },
* "storage" = "Drupal\entity\EntityDisplayModeStorageController" * "storage" = "Drupal\entity\EntityDisplayModeStorageController"
* }, * },
* config_prefix = "entity.form_mode", * config_prefix = "entity.form_mode",
@ -46,4 +53,17 @@ use Drupal\entity\EntityFormModeInterface;
*/ */
class EntityFormMode extends EntityDisplayModeBase implements EntityFormModeInterface { class EntityFormMode extends EntityDisplayModeBase implements EntityFormModeInterface {
/**
* {@inheritdoc}
*/
public function uri() {
return array(
'path' => 'admin/structure/display-modes/form/manage/' . $this->id(),
'options' => array(
'entity_type' => $this->entityType,
'entity' => $this,
),
);
}
} }

View File

@ -35,6 +35,13 @@ use Drupal\entity\EntityViewModeInterface;
* label = @Translation("View mode"), * label = @Translation("View mode"),
* module = "entity", * module = "entity",
* controllers = { * controllers = {
* "list" = "Drupal\entity\EntityDisplayModeListController",
* "access" = "Drupal\entity\EntityDisplayModeAccessController",
* "form" = {
* "add" = "Drupal\entity\Form\EntityDisplayModeAddForm",
* "edit" = "Drupal\entity\Form\EntityDisplayModeEditForm",
* "delete" = "Drupal\entity\Form\EntityDisplayModeDeleteForm"
* },
* "storage" = "Drupal\entity\EntityDisplayModeStorageController" * "storage" = "Drupal\entity\EntityDisplayModeStorageController"
* }, * },
* config_prefix = "entity.view_mode", * config_prefix = "entity.view_mode",
@ -47,4 +54,17 @@ use Drupal\entity\EntityViewModeInterface;
*/ */
class EntityViewMode extends EntityDisplayModeBase implements EntityViewModeInterface { class EntityViewMode extends EntityDisplayModeBase implements EntityViewModeInterface {
/**
* {@inheritdoc}
*/
public function uri() {
return array(
'path' => 'admin/structure/display-modes/view/manage/' . $this->id(),
'options' => array(
'entity_type' => $this->entityType,
'entity' => $this,
),
);
}
} }

View File

@ -0,0 +1,104 @@
<?php
/**
* @file
* Contains \Drupal\entity\Tests\EntityDisplayModeTest.
*/
namespace Drupal\entity\Tests;
use Drupal\simpletest\WebTestBase;
/**
* Tests the entity display mode configuration entities.
*/
class EntityDisplayModeTest extends WebTestBase {
/**
* Modules to enable.
*
* @var array
*/
public static $modules = array('entity_test');
public static function getInfo() {
return array(
'name' => 'Entity display modes UI',
'description' => 'Tests the entity display modes UI.',
'group' => 'Entity',
);
}
/**
* Tests the EntityViewMode user interface.
*/
public function testEntityViewModeUI() {
// Test the listing page.
$this->drupalGet('admin/structure/display-modes/view');
$this->assertResponse(403);
$this->drupalLogin($this->drupalCreateUser(array('administer display modes')));
$this->drupalGet('admin/structure/display-modes/view');
$this->assertResponse(200);
$this->drupalGet('admin/structure/display-modes/view/add/entity_test');
$this->assertResponse(404);
$this->drupalGet('admin/structure/display-modes/view/add');
$this->assertNoLink(t('Test entity'), 'An entity type with no render controller cannot have view modes.');
// Test adding a view mode.
$this->clickLink(t('Test render entity'));
$edit = array(
'id' => strtolower($this->randomName()),
'label' => $this->randomString(),
);
$this->drupalPost(NULL, $edit, t('Save'));
$this->assertRaw(t('Saved the %label view mode.', array('%label' => $edit['label'])));
// Test editing the view mode.
$this->drupalGet('admin/structure/display-modes/view/manage/entity_test_render.' . $edit['id']);
// Test deleting the view mode.
$this->drupalPost(NULL, NULL, t('Delete'));
$this->assertRaw(t('Are you sure you want to delete the %label view mode?', array('%label' => $edit['label'])));
$this->drupalPost(NULL, NULL, t('Delete'));
$this->assertRaw(t('Deleted the %label view mode.', array('%label' => $edit['label'])));
}
/**
* Tests the EntityFormMode user interface.
*/
public function testEntityFormModeUI() {
// Test the listing page.
$this->drupalGet('admin/structure/display-modes/form');
$this->assertResponse(403);
$this->drupalLogin($this->drupalCreateUser(array('administer display modes')));
$this->drupalGet('admin/structure/display-modes/form');
$this->assertResponse(200);
$this->drupalGet('admin/structure/display-modes/form/add/entity_test_render');
$this->assertResponse(404);
$this->drupalGet('admin/structure/display-modes/form/add');
$this->assertNoLink(t('Test render entity'), 'An entity type with no form controller cannot have form modes.');
// Test adding a form mode.
$this->clickLink(t('Test entity'));
$edit = array(
'id' => strtolower($this->randomName()),
'label' => $this->randomString(),
);
$this->drupalPost(NULL, $edit, t('Save'));
$this->assertRaw(t('Saved the %label form mode.', array('%label' => $edit['label'])));
// Test editing the form mode.
$this->drupalGet('admin/structure/display-modes/form/manage/entity_test.' . $edit['id']);
// Test deleting the form mode.
$this->drupalPost(NULL, NULL, t('Delete'));
$this->assertRaw(t('Are you sure you want to delete the %label form mode?', array('%label' => $edit['label'])));
$this->drupalPost(NULL, NULL, t('Delete'));
$this->assertRaw(t('Deleted the %label form mode.', array('%label' => $edit['label'])));
}
}

View File

@ -1,4 +0,0 @@
id: file.full
label: File default
status: '0'
targetEntityType: file

View File

@ -2184,9 +2184,6 @@ function system_update_8056() {
'search_result' => 'Search result', 'search_result' => 'Search result',
'print' => 'Print', 'print' => 'Print',
), ),
'file' => array(
'full' => 'File default',
),
'comment' => array( 'comment' => array(
'full' => 'Full comment', 'full' => 'Full comment',
), ),
@ -2197,9 +2194,6 @@ function system_update_8056() {
'taxonomy_term' => array( 'taxonomy_term' => array(
'full' => 'Taxonomy term page', 'full' => 'Taxonomy term page',
), ),
'taxonomy_vocabulary' => array(
'full' => 'Taxonomy vocabulary',
),
); );
foreach ($entity_view_modes as $entity_type => $view_modes) { foreach ($entity_view_modes as $entity_type => $view_modes) {

View File

@ -1,4 +0,0 @@
id: vocabulary.full
label: Taxonomy vocabulary
status: '0'
targetEntityType: taxonomy_vocabulary