Issue #2050367 by amateescu: FieldInstanceFormBase is useless.

8.0.x
Alex Pott 2013-07-28 10:48:30 +02:00
parent 7aae5d35ca
commit 94cf43e98f
2 changed files with 66 additions and 87 deletions

View File

@ -7,15 +7,65 @@
namespace Drupal\field_ui\Form;
use Drupal\Core\Controller\ControllerInterface;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Entity\EntityManager;
use Drupal\Core\Entity\EntityNG;
use Drupal\Core\Form\FormInterface;
use Drupal\Core\Language\Language;
use Drupal\field\FieldInstanceInterface;
use Drupal\field\Plugin\Type\Widget\WidgetPluginManager;
use Drupal\field_ui\FieldUI;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Provides a form for the field instance settings form.
*/
class FieldInstanceEditForm extends FieldInstanceFormBase {
class FieldInstanceEditForm implements FormInterface, ControllerInterface {
/**
* The field instance being edited.
*
* @var \Drupal\field\FieldInstanceInterface
*/
protected $instance;
/**
* The field widget plugin manager.
*
* @var \Drupal\field\Plugin\Type\Widget\WidgetPluginManager
*/
protected $widgetManager;
/**
* The entity manager.
*
* @var \Drupal\Core\Entity\EntityManager
*/
protected $entityManager;
/**
* Constructs a new field instance form.
*
* @param \Drupal\Core\Entity\EntityManager $entity_manager
* The entity manager.
* @param \Drupal\field\Plugin\Type\Widget\WidgetPluginManager $widget_manager
* The field widget plugin manager.
*/
public function __construct(EntityManager $entity_manager, WidgetPluginManager $widget_manager) {
$this->entityManager = $entity_manager;
$this->widgetManager = $widget_manager;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static(
$container->get('plugin.manager.entity'),
$container->get('plugin.manager.field.widget')
);
}
/**
* {@inheritdoc}
@ -28,7 +78,7 @@ class FieldInstanceEditForm extends FieldInstanceFormBase {
* {@inheritdoc}
*/
public function buildForm(array $form, array &$form_state, FieldInstanceInterface $field_instance = NULL) {
parent::buildForm($form, $form_state, $field_instance);
$this->instance = $form_state['instance'] = $field_instance;
$bundle = $this->instance['bundle'];
$entity_type = $this->instance['entity_type'];
@ -267,4 +317,18 @@ class FieldInstanceEditForm extends FieldInstanceFormBase {
return $item;
}
/**
* Returns the next redirect path in a multipage sequence.
*
* @return string|array
* Either the next path, or an array of redirect paths.
*/
protected function getNextDestination() {
$next_destination = FieldUI::getNextDestination();
if (empty($next_destination)) {
$next_destination = $this->entityManager->getAdminPath($this->instance->entity_type, $this->instance->bundle) . '/fields';
}
return $next_destination;
}
}

View File

@ -1,85 +0,0 @@
<?php
/**
* @file
* Contains \Drupal\field_ui\Form\FieldInstanceFormBase.
*/
namespace Drupal\field_ui\Form;
use Drupal\Core\Form\FormInterface;
use Drupal\Core\Controller\ControllerInterface;
use Drupal\Core\Entity\EntityManager;
use Drupal\field\Plugin\Type\Widget\WidgetPluginManager;
use Drupal\field\FieldInstanceInterface;
use Drupal\field_ui\FieldUI;
use Symfony\Component\DependencyInjection\ContainerInterface;
abstract class FieldInstanceFormBase implements FormInterface, ControllerInterface {
/**
* The field instance being edited.
*
* @var \Drupal\field\FieldInstanceInterface
*/
protected $instance;
/**
* The field widget plugin manager.
*
* @var \Drupal\field\Plugin\Type\Widget\WidgetPluginManager
*/
protected $widgetManager;
/**
* The entity manager.
*
* @var \Drupal\Core\Entity\EntityManager
*/
protected $entityManager;
/**
* Constructs a new field instance form.
*
* @param \Drupal\Core\Entity\EntityManager $entity_manager
* The entity manager.
* @param \Drupal\field\Plugin\Type\Widget\WidgetPluginManager $widget_manager
* The field widget plugin manager.
*/
public function __construct(EntityManager $entity_manager, WidgetPluginManager $widget_manager) {
$this->entityManager = $entity_manager;
$this->widgetManager = $widget_manager;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static(
$container->get('plugin.manager.entity'),
$container->get('plugin.manager.field.widget')
);
}
/**
* {@inheritdoc}
*/
public function buildForm(array $form, array &$form_state, FieldInstanceInterface $field_instance = NULL) {
$this->instance = $form_state['instance'] = $field_instance;
}
/**
* Returns the next redirect path in a multipage sequence.
*
* @return string|array
* Either the next path, or an array of redirect paths.
*/
protected function getNextDestination() {
$next_destination = FieldUI::getNextDestination();
if (empty($next_destination)) {
$next_destination = $this->entityManager->getAdminPath($this->instance->entity_type, $this->instance->bundle) . '/fields';
}
return $next_destination;
}
}