Commit c4b66585 authored by alexpott's avatar alexpott

Issue #1982980 by ParisLiakos, larowlan, dawehner, tim.plunkett: Move...

Issue #1982980 by ParisLiakos, larowlan, dawehner, tim.plunkett: Move entity_get_form() to Drupal\Core\Entity\EntityManager::getForm().
parent 1a416d44
......@@ -485,11 +485,12 @@ function entity_form_submit(EntityInterface $entity, $operation = 'default', &$f
*
* @return
* The processed form for the given entity and operation.
*
* @deprecated Use Drupal::entityManager()->getForm() or _entity_form from a
* routing.yml file instead of a page callback.
*/
function entity_get_form(EntityInterface $entity, $operation = 'default', array $form_state = array()) {
$form_state += entity_form_state_defaults($entity, $operation);
$form_id = $form_state['build_info']['callback_object']->getFormID();
return drupal_build_form($form_id, $form_state);
return Drupal::entityManager()->getForm($entity, $operation, $form_state);
}
/**
......
......@@ -235,6 +235,33 @@ protected function getController($entity_type, $controller_type) {
return $this->controllers[$controller_type][$entity_type];
}
/**
* Returns the built and processed entity form for the given entity.
*
* @param \Drupal\Core\Entity\EntityInterface $entity
* The entity to be created or edited.
* @param string $operation
* (optional) The operation identifying the form variation to be returned.
* Defaults to 'default'.
* @param array $form_state
* (optional) An associative array containing the current state of the form.
* Use this to pass additional information to the form, such as the
* langcode. Defaults to an empty array.
* @code
* $form_state['langcode'] = $langcode;
* $manager = Drupal::entityManager();
* $form = $manager->getForm($entity, 'default', $form_state);
* @endcode
*
* @return array
* The processed form for the given entity and operation.
*/
public function getForm(EntityInterface $entity, $operation = 'default', array $form_state = array()) {
$form_state += entity_form_state_defaults($entity, $operation);
$form_id = $form_state['build_info']['callback_object']->getFormID();
return drupal_build_form($form_id, $form_state);
}
/**
* Returns the administration path for an entity type's bundle.
*
......
......@@ -97,7 +97,7 @@ public function feedAdd() {
'refresh' => 3600,
'block' => 5,
));
return entity_get_form($feed);
return $this->entityManager->getForm($feed);
}
/**
......
......@@ -54,7 +54,7 @@ function block_admin_add($plugin_id, $theme) {
'plugin' => $plugin_id,
'theme' => $theme,
));
return entity_get_form($entity);
return Drupal::entityManager()->getForm($entity);
}
/**
......@@ -84,5 +84,5 @@ function block_admin_edit(Block $entity) {
// Get the block label for the page title.
drupal_set_title(t("Configure %label block in %theme", array('%label' => $entity->label(), '%theme' => $theme_title)), PASS_THROUGH);
return entity_get_form($entity);
return Drupal::entityManager()->getForm($entity);
}
......@@ -17,7 +17,7 @@
*/
function custom_block_type_add() {
$block_type = entity_create('custom_block_type', array());
return entity_get_form($block_type);
return Drupal::entityManager()->getForm($block_type);
}
/**
......@@ -32,7 +32,7 @@ function custom_block_type_add() {
* @see custom_block_menu()
*/
function custom_block_type_edit(CustomBlockType $block_type) {
return entity_get_form($block_type);
return Drupal::entityManager()->getForm($block_type);
}
/**
......
......@@ -42,7 +42,7 @@ function template_preprocess_custom_block_add_list(&$variables) {
*/
function custom_block_edit(CustomBlock $block) {
drupal_set_title(t('Edit custom block %label', array('%label' => $block->label())), PASS_THROUGH);
return entity_get_form($block);
return Drupal::entityManager()->getForm($block);
}
/**
......
......@@ -7,6 +7,7 @@
namespace Drupal\custom_block\Controller;
use Drupal\Component\Plugin\PluginManagerInterface;
use Drupal\Core\Controller\ControllerInterface;
use Drupal\Core\Entity\EntityStorageControllerInterface;
use Drupal\custom_block\CustomBlockTypeInterface;
......@@ -16,11 +17,11 @@
class CustomBlockController implements ControllerInterface {
/**
* Current request object.
* The entity manager.
*
* @var \Symfony\Component\HttpFoundation\Request
* @var \Drupal\Component\Plugin\PluginManagerInterface
*/
protected $request;
protected $entityManager;
/**
* The custom block storage controller.
......@@ -42,7 +43,7 @@ class CustomBlockController implements ControllerInterface {
public static function create(ContainerInterface $container) {
$entity_manager = $container->get('plugin.manager.entity');
return new static(
$container->get('request'),
$entity_manager,
$entity_manager->getStorageController('custom_block'),
$entity_manager->getStorageController('custom_block_type')
);
......@@ -51,17 +52,17 @@ public static function create(ContainerInterface $container) {
/**
* Constructs a CustomBlock object.
*
* @param \Symfony\Component\HttpFoundation\Request $request
* Current request.
* @param \Drupal\Component\Plugin\PluginManagerInterface $entity_manager
* The entity manager.
* @param \Drupal\Core\Entity\EntityStorageControllerInterface $custom_block_storage
* The custom block storage controller.
* @param \Drupal\Core\Entity\EntityStorageControllerInterface $custom_block_type_storage
* The custom block type storage controller.
*/
public function __construct(Request $request, EntityStorageControllerInterface $custom_block_storage, EntityStorageControllerInterface $custom_block_type_storage) {
$this->request = $request;
public function __construct(PluginManagerInterface $entity_manager, EntityStorageControllerInterface $custom_block_storage, EntityStorageControllerInterface $custom_block_type_storage) {
$this->customBlockStorage = $custom_block_storage;
$this->customBlockTypeStorage = $custom_block_type_storage;
$this->entityManager = $entity_manager;
}
/**
......@@ -87,11 +88,13 @@ public function add() {
*
* @param \Drupal\custom_block\CustomBlockTypeInterface $custom_block_type
* The custom block type to add.
* @param \Symfony\Component\HttpFoundation\Request $request
* The current request object.
*
* @return array
* A form array as expected by drupal_render().
*/
public function addForm(CustomBlockTypeInterface $custom_block_type) {
public function addForm(CustomBlockTypeInterface $custom_block_type, Request $request) {
// @todo Remove this when https://drupal.org/node/1981644 is in.
drupal_set_title(t('Add %type custom block', array(
'%type' => $custom_block_type->label()
......@@ -99,13 +102,13 @@ public function addForm(CustomBlockTypeInterface $custom_block_type) {
$block = $this->customBlockStorage->create(array(
'type' => $custom_block_type->id()
));
if (($theme = $this->request->attributes->get('theme')) && in_array($theme, array_keys(list_themes()))) {
if (($theme = $request->attributes->get('theme')) && in_array($theme, array_keys(list_themes()))) {
// We have navigated to this page from the block library and will keep track
// of the theme for redirecting the user to the configuration page for the
// newly created block in the given theme.
$block->setTheme($theme);
}
return entity_get_form($block);
return $this->entityManager->getForm($block);
}
}
......@@ -729,7 +729,7 @@ function comment_node_page_additions(EntityInterface $node) {
function comment_add(EntityInterface $node, $pid = NULL) {
$values = array('nid' => $node->nid, 'pid' => $pid, 'node_type' => 'comment_node_' . $node->type);
$comment = entity_create('comment', $values);
return entity_get_form($comment);
return Drupal::entityManager()->getForm($comment);
}
/**
......
......@@ -28,7 +28,7 @@ class ConfigTestController {
*/
public function edit(ConfigTest $config_test) {
drupal_set_title(String::format('Edit %label', array('%label' => $config_test->label())), PASS_THROUGH);
return entity_get_form($config_test);
return \Drupal::entityManager()->getForm($config_test);
}
/**
......
......@@ -48,7 +48,7 @@ function contact_site_page(Category $category = NULL) {
$message = entity_create('contact_message', array(
'category' => $category->id(),
));
return entity_get_form($message);
return Drupal::entityManager()->getForm($message);
}
/**
......@@ -78,7 +78,7 @@ function contact_personal_page($recipient) {
'recipient' => $recipient,
'category' => 'personal',
));
return entity_get_form($message);
return Drupal::entityManager()->getForm($message);
}
/**
......
......@@ -208,7 +208,7 @@ function field_test_entity_add($fttype) {
$fttype = str_replace('-', '_', $fttype);
$entity = field_test_create_entity(NULL, NULL, $fttype);
drupal_set_title(t('Create test_entity @bundle', array('@bundle' => $fttype)), PASS_THROUGH);
return entity_get_form($entity);
return Drupal::entityManager()->getForm($entity);
}
/**
......@@ -216,7 +216,7 @@ function field_test_entity_add($fttype) {
*/
function field_test_entity_edit(TestEntity $entity) {
drupal_set_title(t('test_entity @ftid revision @ftvid', array('@ftid' => $entity->ftid, '@ftvid' => $entity->ftvid)), PASS_THROUGH);
return entity_get_form($entity);
return Drupal::entityManager()->getForm($entity);
}
/**
......
......@@ -29,7 +29,7 @@ function menu_overview_page() {
*/
function menu_menu_add() {
$menu = entity_create('menu', array());
return entity_get_form($menu);
return Drupal::entityManager()->getForm($menu);
}
/**
......@@ -45,7 +45,7 @@ function menu_menu_add() {
*/
function menu_menu_edit(Menu $menu) {
drupal_set_title(t('Edit menu %label', array('%label' => $menu->label())), PASS_THROUGH);
return entity_get_form($menu);
return Drupal::entityManager()->getForm($menu);
}
/**
......@@ -387,5 +387,5 @@ function menu_link_add(Menu $menu) {
'menu_name' => $menu->id(),
));
drupal_set_title(t('Add menu link'));
return entity_get_form($menu_link);
return Drupal::entityManager()->getForm($menu_link);
}
......@@ -92,7 +92,7 @@ function node_add($node_type) {
'langcode' => $langcode ? $langcode : language_default()->langcode,
))->getBCEntity();
drupal_set_title(t('Create @name', array('@name' => $node_type->name)), PASS_THROUGH);
return entity_get_form($node);
return Drupal::entityManager()->getForm($node);
}
/**
......
......@@ -38,7 +38,7 @@ function testUpdateAllowedValues() {
// All three options appear.
$entity = entity_create('entity_test', array());
$form = entity_get_form($entity);
$form = \Drupal::entityManager()->getForm($entity);
$this->assertTrue(!empty($form[$this->fieldName][$langcode][1]), 'Option 1 exists');
$this->assertTrue(!empty($form[$this->fieldName][$langcode][2]), 'Option 2 exists');
$this->assertTrue(!empty($form[$this->fieldName][$langcode][3]), 'Option 3 exists');
......@@ -64,7 +64,7 @@ function testUpdateAllowedValues() {
$this->field['settings']['allowed_values'] = array(2 => 'Two');
field_update_field($this->field);
$entity = entity_create('entity_test', array());
$form = entity_get_form($entity);
$form = \Drupal::entityManager()->getForm($entity);
$this->assertTrue(empty($form[$this->fieldName][$langcode][1]), 'Option 1 does not exist');
$this->assertTrue(!empty($form[$this->fieldName][$langcode][2]), 'Option 2 exists');
$this->assertTrue(empty($form[$this->fieldName][$langcode][3]), 'Option 3 does not exist');
......@@ -72,7 +72,7 @@ function testUpdateAllowedValues() {
// Completely new options appear.
$this->field['settings']['allowed_values'] = array(10 => 'Update', 20 => 'Twenty');
field_update_field($this->field);
$form = entity_get_form($entity);
$form = \Drupal::entityManager()->getForm($entity);
$this->assertTrue(empty($form[$this->fieldName][$langcode][1]), 'Option 1 does not exist');
$this->assertTrue(empty($form[$this->fieldName][$langcode][2]), 'Option 2 does not exist');
$this->assertTrue(empty($form[$this->fieldName][$langcode][3]), 'Option 3 does not exist');
......@@ -95,7 +95,7 @@ function testUpdateAllowedValues() {
))
->save();
$entity = entity_create('entity_test', array());
$form = entity_get_form($entity);
$form = \Drupal::entityManager()->getForm($entity);
$this->assertTrue(!empty($form[$this->fieldName][$langcode][1]), 'Option 1 exists');
$this->assertTrue(!empty($form[$this->fieldName][$langcode][2]), 'Option 2 exists');
$this->assertTrue(!empty($form[$this->fieldName][$langcode][3]), 'Option 3 exists');
......
......@@ -175,7 +175,7 @@ function shortcut_set_switch_submit($form, &$form_state) {
*/
function shortcut_set_add() {
$entity = entity_create('shortcut', array());
return entity_get_form($entity);
return Drupal::entityManager()->getForm($entity);
}
/**
......
......@@ -79,7 +79,7 @@ function testEntityFormLanguage() {
// Explicitly set form langcode.
$langcode = $this->langcodes[0];
$form_state['langcode'] = $langcode;
entity_get_form($node, 'default', $form_state);
\Drupal::entityManager()->getForm($node, 'default', $form_state);
$form_langcode = \Drupal::state()->get('entity_test.form_langcode') ?: FALSE;
$this->assertTrue($langcode == $form_langcode, 'Form language is the same as the language parameter.');
......
......@@ -257,7 +257,7 @@ function entity_test_form_node_form_alter(&$form, &$form_state, $form_id) {
function entity_test_add($entity_type) {
drupal_set_title(t('Create an @type', array('@type' => $entity_type)));
$entity = entity_create($entity_type, array());
return entity_get_form($entity);
return Drupal::entityManager()->getForm($entity);
}
/**
......@@ -273,7 +273,7 @@ function entity_test_add($entity_type) {
*/
function entity_test_edit(EntityInterface $entity) {
drupal_set_title($entity->label(), PASS_THROUGH);
return entity_get_form($entity);
return Drupal::entityManager()->getForm($entity);
}
/**
......
......@@ -2267,8 +2267,8 @@ function form_test_two_instances() {
'langcode' => Language::LANGCODE_NOT_SPECIFIED,
));
$node2 = clone($node1);
$return['node_form_1'] = entity_get_form($node1);
$return['node_form_2'] = entity_get_form($node2);
$return['node_form_1'] = Drupal::entityManager()->getForm($node1);
$return['node_form_2'] = Drupal::entityManager()->getForm($node2);
return $return;
}
......
......@@ -17,7 +17,7 @@ function taxonomy_vocabulary_add() {
// most likely default value until we have better flexible settings.
'langcode' => language_default()->langcode,
));
return entity_get_form($vocabulary);
return Drupal::entityManager()->getForm($vocabulary);
}
/**
......@@ -398,7 +398,7 @@ function taxonomy_term_add($vocabulary) {
if (module_exists('language')) {
$term->langcode = language_get_default_langcode('taxonomy_term', $vocabulary->id());
}
return entity_get_form($term);
return Drupal::entityManager()->getForm($term);
}
/**
......
......@@ -202,7 +202,7 @@ function translation_entity_add_page(EntityInterface $entity, Language $source =
$form_state['translation_entity']['target'] = $target;
$controller = translation_entity_controller($entity->entityType());
$form_state['translation_entity']['translation_form'] = !$controller->getAccess($entity, 'update');
return entity_get_form($entity, $operation, $form_state);
return Drupal::entityManager()->getForm($entity, $operation, $form_state);
}
/**
......@@ -223,7 +223,7 @@ function translation_entity_edit_page(EntityInterface $entity, Language $languag
$operation = isset($info['default_operation']) ? $info['default_operation'] : 'default';
$form_state['langcode'] = $language->langcode;
$form_state['translation_entity']['translation_form'] = TRUE;
return entity_get_form($entity, $operation, $form_state);
return Drupal::entityManager()->getForm($entity, $operation, $form_state);
}
/**
......
......@@ -234,8 +234,8 @@ public function edit(ViewUI $view, $display_id = NULL) {
}
drupal_set_title($name);
$build['edit'] = entity_get_form($view, 'edit', array('display_id' => $display_id));
$build['preview'] = entity_get_form($view, 'preview', array('display_id' => $display_id));
$build['edit'] = $this->entityManager->getForm($view, 'edit', array('display_id' => $display_id));
$build['preview'] = $this->entityManager->getForm($view, 'preview', array('display_id' => $display_id));
return $build;
}
......
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