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 05498f7..d0bf3e2 100644 --- a/core/modules/system/tests/modules/entity_test/entity_test.module +++ b/core/modules/system/tests/modules/entity_test/entity_test.module @@ -213,18 +213,12 @@ function entity_test_menu() { $items[$entity_type . '/add'] = array( 'title' => 'Add an @type', 'title arguments' => array('@type' => $entity_type), - 'page callback' => 'entity_test_add', - 'page arguments' => array($entity_type), - 'access arguments' => array('administer entity_test content'), 'type' => MENU_NORMAL_ITEM, ); $items[$entity_type . '/manage/%' . $entity_type] = array( 'title' => 'Edit @type', 'title arguments' => array('@type' => $entity_type), - 'page callback' => 'entity_test_edit', - 'page arguments' => array(2), - 'access arguments' => array('administer entity_test content'), 'type' => MENU_NORMAL_ITEM, ); @@ -246,39 +240,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() - */ -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() - */ -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/EntityTestSubscriber.php b/core/modules/system/tests/modules/entity_test/lib/Drupal/entity_test/EntityTestSubscriber.php new file mode 100644 index 0000000..d3e942d --- /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( + '_access' => '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( + '_access' => 'administer entity_test content', + )); + $collection->add('entity_test_edit_' . $entity_type, $route); + } + } + +}