Commit 6b265331 authored by alexpott's avatar alexpott

Issue #2238981 by dawehner, effulgentsia, tim.plunkett: Change controllers to...

Issue #2238981 by dawehner, effulgentsia, tim.plunkett: Change controllers to receive route parameters in their signature rather than via $request->attributes.
parent 8f3f79ad
......@@ -79,12 +79,8 @@ public function getFormId() {
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state, $entity_type_id = NULL, $bundle = NULL) {
if ($this->getRequest()->attributes->has('view_mode_name')) {
$this->mode = $this->getRequest()->attributes->get('view_mode_name');
}
return parent::buildForm($form, $form_state, $entity_type_id, $bundle);
public function buildForm(array $form, FormStateInterface $form_state, $entity_type_id = NULL, $bundle = NULL, $view_mode_name = 'default') {
return parent::buildForm($form, $form_state, $entity_type_id, $bundle, $view_mode_name);
}
/**
......
......@@ -117,12 +117,10 @@ protected function getFieldDefinitions() {
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state, $entity_type_id = NULL, $bundle = NULL) {
public function buildForm(array $form, FormStateInterface $form_state, $entity_type_id = NULL, $bundle = NULL, $mode = 'default') {
parent::buildForm($form, $form_state, $entity_type_id, $bundle);
if (empty($this->mode)) {
$this->mode = 'default';
}
$this->mode = $mode;
$field_definitions = $this->getFieldDefinitions();
$extra_fields = $this->getExtraFields();
......
......@@ -78,12 +78,8 @@ public function getFormId() {
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state, $entity_type_id = NULL, $bundle = NULL) {
if ($this->getRequest()->attributes->has('form_mode_name')) {
$this->mode = $this->getRequest()->attributes->get('form_mode_name');
}
return parent::buildForm($form, $form_state, $entity_type_id, $bundle);
public function buildForm(array $form, FormStateInterface $form_state, $entity_type_id = NULL, $bundle = NULL, $form_mode_name = 'default') {
return parent::buildForm($form, $form_state, $entity_type_id, $bundle, $form_mode_name);
}
/**
......
......@@ -47,7 +47,7 @@ public static function create(ContainerInterface $container) {
/**
* Displays the 'Add new entity_test' form.
*
* @param string $entity_type
* @param string $entity_type_id
* Name of the entity type for which a create form should be displayed.
*
* @return array
......@@ -55,10 +55,10 @@ public static function create(ContainerInterface $container) {
*
* @see \Drupal\entity_test\Routing\EntityTestRoutes::routes()
*/
public function testAdd($entity_type) {
$entity = entity_create($entity_type, array());
public function testAdd($entity_type_id) {
$entity = entity_create($entity_type_id, array());
$form = $this->entityFormBuilder()->getForm($entity);
$form['#title'] = $this->t('Create an @type', array('@type' => $entity_type));
$form['#title'] = $this->t('Create an @type', array('@type' => $entity_type_id));
return $form;
}
......@@ -67,14 +67,16 @@ public function testAdd($entity_type) {
*
* @param \Symfony\Component\HttpFoundation\Request $request
* The request object to get entity type from.
* @param string $entity_type_id
* The entity type ID.
*
* @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'));
public function testEdit(Request $request, $entity_type_id) {
$entity = $request->attributes->get($entity_type_id);
$form = $this->entityFormBuilder()->getForm($entity);
$form['#title'] = $entity->label();
return $form;
......
......@@ -26,24 +26,24 @@ public function routes() {
$types[] = 'entity_test_no_id';
$routes = array();
foreach ($types as $entity_type) {
$routes["entity.$entity_type.add_form"] = new Route(
"$entity_type/add",
array('_content' => '\Drupal\entity_test\Controller\EntityTestController::testAdd', 'entity_type' => $entity_type),
foreach ($types as $entity_type_id) {
$routes["entity.$entity_type_id.add_form"] = new Route(
"$entity_type_id/add",
array('_content' => '\Drupal\entity_test\Controller\EntityTestController::testAdd', 'entity_type_id' => $entity_type_id),
array('_permission' => 'administer entity_test content')
);
$routes["entity.$entity_type.edit_form"] = new Route(
"$entity_type/manage/{" . $entity_type . '}',
array('_content' => '\Drupal\entity_test\Controller\EntityTestController::testEdit', '_entity_type' => $entity_type),
$routes["entity.$entity_type_id.edit_form"] = new Route(
"$entity_type_id/manage/{" . $entity_type_id . '}',
array('_content' => '\Drupal\entity_test\Controller\EntityTestController::testEdit', 'entity_type_id' => $entity_type_id),
array('_permission' => 'administer entity_test content'),
array('parameters' => array(
$entity_type => array('type' => 'entity:' . $entity_type),
$entity_type_id => array('type' => 'entity:' . $entity_type_id),
))
);
$routes["entity.$entity_type.admin_form"] = new Route(
"$entity_type/structure/{bundle}",
$routes["entity.$entity_type_id.admin_form"] = new Route(
"$entity_type_id/structure/{bundle}",
array('_content' => '\Drupal\entity_test\Controller\EntityTestController::testAdmin'),
array('_permission' => 'administer entity_test content')
);
......
......@@ -30,15 +30,22 @@
public function init(FormStateInterface $form_state) {
parent::init($form_state);
if ($display_id = \Drupal::request()->attributes->get('display_id')) {
$this->displayID = $display_id;
}
// @todo Remove the need for this.
$form_state->loadInclude('views_ui', 'inc', 'admin');
$form_state->set('view', $this->entity);
}
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state, $display_id = NULL) {
if (isset($display_id) && $form_state->has('display_id') && ($display_id !== $form_state->get('display_id'))) {
throw new \InvalidArgumentException('Mismatch between $form_state->get(\'display_id\') and $display_id.');
}
$this->displayID = $form_state->has('display_id') ? $form_state->get('display_id') : $display_id;
return parent::buildForm($form, $form_state);
}
/**
* {@inheritdoc}
*/
......
......@@ -8,40 +8,12 @@
namespace Drupal\views_ui;
use Drupal\Core\Form\FormStateInterface;
use Drupal\user\TempStoreFactory;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Form controller for the Views preview form.
*/
class ViewPreviewForm extends ViewFormBase {
/**
* The views temp store.
*
* @var \Drupal\user\TempStore
*/
protected $tempStore;
/**
* Constructs a new ViewPreviewForm object.
*
* @param \Drupal\user\TempStoreFactory $temp_store_factory
* The factory for the temp store object.
*/
public function __construct(TempStoreFactory $temp_store_factory) {
$this->tempStore = $temp_store_factory->get('views');
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static(
$container->get('user.tempstore')
);
}
/**
* {@inheritdoc}
*/
......@@ -129,15 +101,6 @@ protected function actions(array $form, FormStateInterface $form_state) {
* Form submission handler for the Preview button.
*/
public function submitPreview($form, FormStateInterface $form_state) {
// Rebuild the form with a pristine $view object.
$view = $this->entity;
// Attempt to load the view from temp store, otherwise create a new one.
if (!$new_view = $this->tempStore->get($view->id())) {
$new_view = new ViewUI($view);
}
$build_info = $form_state->getBuildInfo();
$build_info['args'][0] = $new_view;
$form_state->setBuildInfo($build_info);
$form_state->set('show_preview', TRUE);
$form_state->setRebuild();
}
......
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