Commit 7a08f39b authored by webchick's avatar webchick

Issue #1987694 by ianthomas_uk, disasm, rlmumford, vijaycs85: Convert...

Issue #1987694 by ianthomas_uk, disasm, rlmumford, vijaycs85: Convert entity_test callbacks to a new style controller.
parent 9d31d646
......@@ -248,43 +248,6 @@ function entity_test_form_node_form_alter(&$form, &$form_state, $form_id) {
\Drupal::state()->set('entity_test.form_langcode', $langcode);
}
/**
* Menu callback: displays the 'Add new entity_test' form.
*
* @param string $entity_type
* Name of the entity type for which a create form should be displayed.
*
* @return array
* The processed form for a new entity_test.
*
* @see entity_test_menu()
*
* @deprecated \Drupal\entity_test\Controller\EntityTestController::testAdd()
*/
function entity_test_add($entity_type) {
drupal_set_title(t('Create an @type', array('@type' => $entity_type)));
$entity = entity_create($entity_type);
return \Drupal::service('entity.form_builder')->getForm($entity);
}
/**
* Menu callback: displays the 'Edit existing entity_test' form.
*
* @param \Drupal\Core\Entity\EntityInterface $entity
* The entity to be edited.
*
* @return array
* The processed form for the edited entity.
*
* @see entity_test_menu()
*
* @deprecated \Drupal\entity_test\Controller\EntityTestController::testEdit()
*/
function entity_test_edit(EntityInterface $entity) {
drupal_set_title($entity->label(), PASS_THROUGH);
return \Drupal::service('entity.form_builder')->getForm($entity);
}
/**
* Loads a test entity.
*
......
......@@ -7,31 +7,54 @@
namespace Drupal\entity_test\Controller;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Controller\ControllerBase;
use Symfony\Component\HttpFoundation\Request;
/**
* Controller routines for entity_test routes.
*/
class EntityTestController {
class EntityTestController extends ControllerBase {
/**
* @todo Remove entity_test_add()
* Displays the 'Add new entity_test' form.
*
* @param string $entity_type
* Name of the entity type for which a create form should be displayed.
*
* @return array
* The processed form for a new entity_test.
*
* @see \Drupal\entity_test\Routing\EntityTestRoutes::routes()
*/
public function testAdd($entity_type) {
return entity_test_add($entity_type);
$entity = entity_create($entity_type, array());
$form = $this->entityFormBuilder()->getForm($entity);
$form['#title'] = $this->t('Create an @type', array('@type' => $entity_type));
return $form;
}
/**
* @todo Remove entity_test_edit()
* Displays the 'Edit existing entity_test' form.
*
* @param \Symfony\Component\HttpFoundation\Request $request
* The request object to get entity type from.
*
* @return array
* The processed form for the edited entity.
*
* @see \Drupal\entity_test\Routing\EntityTestRoutes::routes()
*/
public function testEdit(Request $request) {
$entity = $request->attributes->get($request->attributes->get('_entity_type'));
return entity_test_edit($entity);
$form = $this->entityFormBuilder()->getForm($entity);
$form['#title'] = $entity->label();
return $form;
}
/**
* Returns an empty page.
*
* @see \Drupal\entity_test\Routing\EntityTestRoutes::routes()
*/
public function testAdmin() {
return '';
......
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