diff --git a/core/modules/system/tests/modules/entity_test/entity_test.module b/core/modules/system/tests/modules/entity_test/entity_test.module index d16c503..ab74a1f 100644 --- a/core/modules/system/tests/modules/entity_test/entity_test.module +++ b/core/modules/system/tests/modules/entity_test/entity_test.module @@ -269,43 +269,6 @@ function entity_test_form_node_form_alter(&$form, &$form_state, $form_id) { } /** - * 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, array()); - return \Drupal::entityManager()->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::entityManager()->getForm($entity); -} - -/** * Loads a test entity. * * @param int $id diff --git a/core/modules/system/tests/modules/entity_test/entity_test.services.yml b/core/modules/system/tests/modules/entity_test/entity_test.services.yml new file mode 100644 index 0000000..645504c --- /dev/null +++ b/core/modules/system/tests/modules/entity_test/entity_test.services.yml @@ -0,0 +1,5 @@ +services: + entity_test.route_subscriber: + class: Drupal\entity_test\EntityTestSubscriber + tags: + - { name: event_subscriber } diff --git a/core/modules/system/tests/modules/entity_test/lib/Drupal/entity_test/Controller/EntityTest.php b/core/modules/system/tests/modules/entity_test/lib/Drupal/entity_test/Controller/EntityTest.php new file mode 100644 index 0000000..8615e9a --- /dev/null +++ b/core/modules/system/tests/modules/entity_test/lib/Drupal/entity_test/Controller/EntityTest.php @@ -0,0 +1,73 @@ +get('entity_manager')); + } + + /** + * Constructs a UpdateTestController object. + * + * @param \Drupal\Core\Config\ConfigFactory $config_factory + * The factory for configuration objects. + */ + public function __construct(EntityManager $entityManager) { + $this->entityManager = $entityManager; + } + + /** + * 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() + */ + function add($entity_type) { + drupal_set_title(t('Create an @type', array('@type' => $entity_type))); + $entity = entity_create($entity_type, array()); + return $this->entityManager->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() + */ + function edit(EntityInterface $entity) { + drupal_set_title($entity->label(), PASS_THROUGH); + return $this->entityManager->getForm($entity); + } + + +} diff --git a/core/modules/system/tests/modules/entity_test/lib/Drupal/entity_test/Controller/EntityTestController.php b/core/modules/system/tests/modules/entity_test/lib/Drupal/entity_test/Controller/EntityTestController.php index a6a42ee..55b257e 100644 --- a/core/modules/system/tests/modules/entity_test/lib/Drupal/entity_test/Controller/EntityTestController.php +++ b/core/modules/system/tests/modules/entity_test/lib/Drupal/entity_test/Controller/EntityTestController.php @@ -7,27 +7,48 @@ 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 entity_test_menu() */ public function testAdd($entity_type) { - return entity_test_add($entity_type); + $entity = entity_create($entity_type, array()); + $form = $this->entityManager()->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 entity_test_menu() */ public function testEdit(Request $request) { $entity = $request->attributes->get($request->attributes->get('_entity_type')); - return entity_test_edit($entity); + $form = $this->entityManager()->getForm($entity); + $form['#title'] = $entity->label(); + return $form; } /** diff --git a/core/modules/system/tests/modules/entity_test/lib/Drupal/entity_test/EntityTestSubscriber.php b/core/modules/system/tests/modules/entity_test/lib/Drupal/entity_test/EntityTestSubscriber.php new file mode 100644 index 0000000..2fac2d5 --- /dev/null +++ b/core/modules/system/tests/modules/entity_test/lib/Drupal/entity_test/EntityTestSubscriber.php @@ -0,0 +1,52 @@ +getRouteCollection(); + foreach (entity_test_entity_types() as $entity_type) { + $route = new Route('/' . $entity_type . '/add', array( + '_content' => '\Drupal\entity_test\Controller\EntityTest::add',), array( + '_permission' => 'administer entity_test content', + )); + $collection->add('entity_test_add_' . $entity_type, $route); + $route = new Route('/' . $entity_type . '/manage/{entity}', array( + '_content' => '\Drupal\entity_test\Controller\EntityTest::edit',), array( + '_permission' => 'administer entity_test content', + )); + $collection->add('entity_test_edit_' . $entity_type, $route); + } + } + +}