Commit 8355142b authored by alexpott's avatar alexpott

Issue #1987668 by damiankloip, jibran, h3rj4n, mparker17: Convert config_test() module to routes.

parent a74a17a5
......@@ -32,15 +32,11 @@ function config_test_menu() {
);
$items['admin/structure/config_test/add'] = array(
'title' => 'Add test configuration',
'page callback' => 'config_test_add_page',
'access callback' => TRUE,
'type' => MENU_LOCAL_ACTION,
'route_name' => 'config_test_entity_add',
'type' => MENU_SIBLING_LOCAL_TASK,
);
$items['admin/structure/config_test/manage/%config_test'] = array(
'title' => 'Edit test configuration',
'page callback' => 'config_test_edit_page',
'page arguments' => array(4),
'access callback' => TRUE,
'route_name' => 'config_test_entity_edit',
);
$items['admin/structure/config_test/manage/%config_test/edit'] = array(
'title' => 'Edit',
......@@ -48,26 +44,34 @@ function config_test_menu() {
);
$items['admin/structure/config_test/manage/%config_test/delete'] = array(
'title' => 'Delete',
'page callback' => 'drupal_get_form',
'page arguments' => array('config_test_delete_form', 4),
'access callback' => TRUE,
'type' => MENU_LOCAL_TASK,
'route_name' => 'config_test_entity_delete',
);
$items['admin/structure/config_test/manage/%config_test/enable'] = array(
'title' => 'Enable',
'page callback' => 'config_test_entity_enable',
'page arguments' => array(4),
'access callback' => TRUE,
'route_name' => 'config_test_entity_enable',
);
$items['admin/structure/config_test/manage/%config_test/disable'] = array(
'title' => 'Disable',
'page callback' => 'config_test_entity_disable',
'page arguments' => array(4),
'access callback' => TRUE,
'route_name' => 'config_test_entity_disable',
);
return $items;
}
/**
* Implements hook_local_actions()
*/
function config_test_local_actions() {
return array(
array(
'route_name' => 'config_test_entity_add',
'title' => t('Add test configuration'),
'appears_on' => array(
'config_test_list_page',
),
),
);
}
/**
* Loads a ConfigTest object.
*
......@@ -78,58 +82,6 @@ function config_test_load($id) {
return entity_load('config_test', $id);
}
/**
* Page callback: Presents the ConfigTest creation form.
*
* @return array
* A form array as expected by drupal_render().
*/
function config_test_add_page() {
$entity = entity_create('config_test', array());
return entity_get_form($entity);
}
/**
* Page callback: Presents the ConfigTest edit form.
*
* @param Drupal\config_test\Plugin\Core\Entity\ConfigTest $config_test
* The ConfigTest object to edit.
*
* @return array
* A form array as expected by drupal_render().
*/
function config_test_edit_page(ConfigTest $config_test) {
drupal_set_title(format_string('Edit %label', array('%label' => $config_test->label())), PASS_THROUGH);
return entity_get_form($config_test);
}
/**
* Form constructor to delete a ConfigTest object.
*
* @param Drupal\config_test\Plugin\Core\Entity\ConfigTest $config_test
* The ConfigTest object to delete.
*/
function config_test_delete_form($form, &$form_state, ConfigTest $config_test) {
$form_state['config_test'] = $config_test;
$form['id'] = array('#type' => 'value', '#value' => $config_test->id());
return confirm_form($form,
format_string('Are you sure you want to delete %label', array('%label' => $config_test->label())),
'admin/structure/config_test',
NULL,
'Delete'
);
}
/**
* Form submission handler for config_test_delete_form().
*/
function config_test_delete_form_submit($form, &$form_state) {
$form_state['config_test']->delete();
drupal_set_message(format_string('%label configuration has been deleted.', array('%label' => $form_state['config_test']->label())));
$form_state['redirect'] = 'admin/structure/config_test';
}
/**
* Implements hook_cache_flush().
*/
......@@ -147,32 +99,6 @@ function config_test_config_test_create(ConfigTest $config_test) {
}
}
/**
* Enables a ConfigTest object.
*
* @param Drupal\config_test\ConfigTest $config_test
* The ConfigTest object to enable.
*
* @return \Symfony\Component\HttpFoundation\RedirectResponse.
*/
function config_test_entity_enable(ConfigTest $config_test) {
$config_test->enable()->save();
return new RedirectResponse(url('admin/structure/config_test', array('absolute' => TRUE)));
}
/**
* Disables a ConfigTest object.
*
* @param Drupal\config_test\ConfigTest $config_test
* The ConfigTest object to disable.
*
* @return \Symfony\Component\HttpFoundation\RedirectResponse.
*/
function config_test_entity_disable(ConfigTest $config_test) {
$config_test->disable()->save();
return new RedirectResponse(url('admin/structure/config_test', array('absolute' => TRUE)));
}
/**
* Implements hook_entity_info_alter().
*/
......
......@@ -5,3 +5,50 @@ config_test_list_page:
entity_type: 'config_test'
requirements:
_access: 'TRUE'
config_test_entity_add:
pattern: 'admin/structure/config_test/add'
defaults:
_entity_form: 'config_test'
requirements:
_access: 'TRUE'
config_test_entity:
pattern: 'admin/structure/config_test/manage/{config_test}'
defaults:
_controller: '\Drupal\config_test\ConfigTestController::edit'
entity_type: 'config_test'
requirements:
_access: 'TRUE'
config_test_entity_edit:
pattern: 'admin/structure/config_test/manage/{config_test}/edit'
defaults:
_controller: '\Drupal\config_test\ConfigTestController::edit'
entity_type: 'config_test'
requirements:
_access: 'TRUE'
config_test_entity_enable:
pattern: 'admin/structure/config_test/manage/{config_test}/enable'
defaults:
_content: '\Drupal\config_test\ConfigTestController::enable'
entity_type: 'config_test'
requirements:
_access: 'TRUE'
config_test_entity_disable:
pattern: 'admin/structure/config_test/manage/{config_test}/disable'
defaults:
_content: '\Drupal\config_test\ConfigTestController::disable'
entity_type: 'config_test'
requirements:
_access: 'TRUE'
config_test_entity_delete:
pattern: 'admin/structure/config_test/manage/{config_test}/delete'
defaults:
_form: '\Drupal\config_test\Form\ConfigTestDeleteForm'
entity_type: 'config_test'
requirements:
_access: 'TRUE'
<?php
/**
* @file
* Contains \Drupal\config_test\ConfigTestController.
*/
namespace Drupal\config_test;
use Drupal\config_test\Plugin\Core\Entity\ConfigTest;
use Drupal\Component\Utility\String;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpFoundation\RedirectResponse;
/**
* Route controller class for the config_test module.
*/
class ConfigTestController {
/**
* Presents the ConfigTest edit form.
*
* @param \Drupal\config_test\Plugin\Core\Entity\ConfigTest $config_test
* The ConfigTest object to edit.
*
* @return array
* A form array as expected by drupal_render().
*/
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);
}
/**
* Enables a ConfigTest object.
*
* @param \Drupal\config_test\ConfigTest $config_test
* The ConfigTest object to enable.
*
* @return \Symfony\Component\HttpFoundation\RedirectResponse
* A redirect response to the config_test listing page.
*/
function enable(ConfigTest $config_test) {
$config_test->enable()->save();
return new RedirectResponse(url('admin/structure/config_test', array('absolute' => TRUE)));
}
/**
* Disables a ConfigTest object.
*
* @param \Drupal\config_test\ConfigTest $config_test
* The ConfigTest object to disable.
*
* @return \Symfony\Component\HttpFoundation\RedirectResponse
* A redirect response to the config_test listing page.
*/
function disable(ConfigTest $config_test) {
$config_test->disable()->save();
return new RedirectResponse(url('admin/structure/config_test', array('absolute' => TRUE)));
}
}
<?php
/**
* @file
* Contains \Drupal\config_test\Plugin\Core\Entity\ConfigTestInterface.
*/
namespace Drupal\config_test;
use Drupal\Core\Config\Entity\ConfigEntityInterface;
/**
* Provides an interface defining a config_test entity.
*/
interface ConfigTestInterface extends ConfigEntityInterface {
}
<?php
/**
* @file
* Contains \Drupal\config_test\Form\ConfigTestDeleteForm.
*/
namespace Drupal\config_test\Form;
use Drupal\Component\Utility\String;
use Drupal\Core\Form\ConfirmFormBase;
use Drupal\config_test\ConfigTestInterface;
/**
* Delete confirmation form for config_test entities.
*/
class ConfigTestDeleteForm extends ConfirmFormBase {
/**
* The config_test entity to be deleted.
*
* @var \Drupal\config_test\Plugin\Core\Entity\ConfigTest.
*/
protected $configTest;
/**
* {@inheritdoc}
*/
protected function getQuestion() {
return t('Are you sure you want to delete %label', array('%label' => $this->configTest->label()));
}
/**
* {@inheritdoc}
*/
protected function getConfirmText() {
return t('Delete');
}
/**
* {@inheritdoc}
*/
protected function getCancelPath() {
return 'admin/structure/config_test';
}
/**
* {@inheritdoc}
*/
public function getFormID() {
return 'config_test_delete_form';
}
/**
* Implements \Drupal\Drupal\Core\Form\ConfirmFormBase::buildForm().
*
* @param \Drupal\config_test\ConfigTestInterface $config_test
* (optional) The ConfigTestInterface object to delete.
*/
public function buildForm(array $form, array &$form_state, ConfigTestInterface $config_test = NULL) {
$this->configTest = $config_test;
return parent::buildForm($form, $form_state);
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, array &$form_state) {
$this->configTest->delete();
drupal_set_message(String::format('%label configuration has been deleted.', array('%label' => $this->configTest->label())));
$form_state['redirect'] = 'admin/structure/config_test';
}
}
......@@ -10,6 +10,7 @@
use Drupal\Core\Config\Entity\ConfigEntityBase;
use Drupal\Core\Entity\Annotation\EntityType;
use Drupal\Core\Annotation\Translation;
use Drupal\config_test\ConfigTestInterface;
/**
* Defines the ConfigTest configuration entity.
......@@ -35,7 +36,7 @@
* }
* )
*/
class ConfigTest extends ConfigEntityBase {
class ConfigTest extends ConfigEntityBase implements ConfigTestInterface {
/**
* The machine name for the configuration entity.
......
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