class EdgeEntityDisplaySettingsForm in Apigee Edge 8
Configuration form for Apigee entities display settings.
Hierarchy
- class \Drupal\Core\Form\FormBase implements ContainerInjectionInterface, FormInterface uses DependencySerializationTrait, LoggerChannelTrait, MessengerTrait, LinkGeneratorTrait, RedirectDestinationTrait, UrlGeneratorTrait, StringTranslationTrait
- class \Drupal\Core\Form\ConfigFormBase uses ConfigFormBaseTrait
- class \Drupal\apigee_edge\Form\EdgeEntityDisplaySettingsForm implements BaseFormIdInterface
- class \Drupal\Core\Form\ConfigFormBase uses ConfigFormBaseTrait
Expanded class hierarchy of EdgeEntityDisplaySettingsForm
1 file declares its use of EdgeEntityDisplaySettingsForm
- EdgeEntityDisplaySettingsFormTest.php in tests/
src/ Kernel/ Form/ EdgeEntityDisplaySettingsFormTest.php
2 string references to 'EdgeEntityDisplaySettingsForm'
- apigee_edge.routing.yml in ./
apigee_edge.routing.yml - apigee_edge.routing.yml
- apigee_edge_teams.routing.yml in modules/
apigee_edge_teams/ apigee_edge_teams.routing.yml - modules/apigee_edge_teams/apigee_edge_teams.routing.yml
File
- src/
Form/ EdgeEntityDisplaySettingsForm.php, line 38
Namespace
Drupal\apigee_edge\FormView source
class EdgeEntityDisplaySettingsForm extends ConfigFormBase implements BaseFormIdInterface {
/**
* The entity type manager.
*
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
*/
protected $entityTypeManager;
/**
* The module handler.
*
* @var \Drupal\Core\Extension\ModuleHandlerInterface
*/
protected $moduleHandler;
/**
* The entity display repository.
*
* @var \Drupal\Core\Entity\EntityDisplayRepositoryInterface
*/
protected $entityDisplayRepository;
/**
* The entity type ID.
*
* @var string
*/
protected $entityTypeId;
/**
* The route match.
*
* @var \Drupal\Core\Routing\RouteMatchInterface
*/
protected $routeMatch;
/**
* AppDisplaySettingsForm constructor.
*
* @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
* The config factory.
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
* The entity type manager.
* @param \Drupal\Core\Entity\EntityDisplayRepositoryInterface $entity_display_repository
* The entity display repository.
* @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
* The module handler.
* @param \Drupal\Core\Routing\RouteMatchInterface $route_match
* The route match.
*/
public function __construct(ConfigFactoryInterface $config_factory, EntityTypeManagerInterface $entity_type_manager, EntityDisplayRepositoryInterface $entity_display_repository, ModuleHandlerInterface $module_handler, RouteMatchInterface $route_match) {
parent::__construct($config_factory);
$this->entityTypeManager = $entity_type_manager;
$this->moduleHandler = $module_handler;
$this->entityDisplayRepository = $entity_display_repository;
$this->routeMatch = $route_match;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static($container
->get('config.factory'), $container
->get('entity_type.manager'), $container
->get('entity_display.repository'), $container
->get('module_handler'), $container
->get('current_route_match'));
}
/**
* {@inheritdoc}
*/
public function getBaseFormId() {
return 'apigee_edge_display_settings_form';
}
/**
* {@inheritdoc}
*/
public function getFormId() {
$entity_type_id = $this->routeMatch
->getParameter('entity_type_id');
return "apigee_edge_display_settings_form.{$entity_type_id}";
}
/**
* {@inheritdoc}
*/
protected function getEditableConfigNames() {
return [
'apigee_edge.display_settings',
];
}
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state, $entity_type_id = NULL) {
$this->entityTypeId = $entity_type_id;
/** @var \Drupal\Core\Entity\EntityTypeInterface $entity_type */
$entity_type = $this->entityTypeManager
->getDefinition($entity_type_id);
$config = $this
->configFactory()
->get("apigee_edge.display_settings.{$entity_type_id}");
$form['display_settings'] = [
'#type' => 'fieldset',
'#title' => $this
->t('Configure the display for @label listing page.', [
'@label' => $entity_type
->getPluralLabel(),
]),
'#collapsible' => FALSE,
];
$form['display_settings']['display_type'] = [
'#type' => 'select',
'#title' => $this
->t('Type'),
'#default_value' => $config
->get('display_type'),
'#required' => TRUE,
'#description' => $this
->t('Select the <em>Default</em> type to display a table of entities with links to entity operations. Select <em>Display mode</em> to configure a custom display.'),
'#options' => [
EdgeEntityListBuilder::DEFAULT_DISPLAY_TYPE => $this
->t('Default'),
EdgeEntityListBuilder::VIEW_MODE_DISPLAY_TYPE => $this
->t('Display mode'),
],
];
$form['display_settings']['display_mode_container'] = [
'#type' => 'container',
'#states' => [
'visible' => [
':input[name="display_type"]' => [
'value' => 'view_mode',
],
],
],
];
$display_modes = [
'default' => $this
->t('Default'),
];
foreach ($this->entityDisplayRepository
->getViewModes($entity_type
->id()) as $name => $view_mode) {
$display_modes[$name] = $view_mode['label'];
}
$form['display_settings']['display_mode_container']['view_mode'] = [
'#type' => 'select',
'#title' => $this
->t('Display mode'),
'#default_value' => $config
->get('view_mode'),
'#description' => $this
->t('Select the display mode.', [
':uri' => '#',
]),
'#options' => $display_modes,
];
if ($this->moduleHandler
->moduleExists('field_ui')) {
$form['display_settings']['display_mode_container']['display_mode_help'] = [
'#theme' => 'item_list',
'#items' => [
[
'#markup' => $this
->t('<a href=":uri">Click here</a> to configure the display.', [
':uri' => Url::fromRoute("entity.entity_view_display.{$entity_type->id()}.default")
->toString(),
]),
],
[
'#markup' => $this
->t('<a href=":uri">Click here</a> to add a new display mode.', [
':uri' => Url::fromRoute('entity.entity_view_mode.collection')
->toString(),
]),
],
],
];
}
return parent::buildForm($form, $form_state);
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
$this
->configFactory()
->getEditable("apigee_edge.display_settings.{$this->entityTypeId}")
->set('display_type', $form_state
->getValue('display_type'))
->set('view_mode', $form_state
->getValue('view_mode'))
->save();
parent::submitForm($form, $form_state);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ConfigFormBaseTrait:: |
protected | function | Retrieves a configuration object. | |
DependencySerializationTrait:: |
protected | property | An array of entity type IDs keyed by the property name of their storages. | |
DependencySerializationTrait:: |
protected | property | An array of service IDs keyed by property name used for serialization. | |
DependencySerializationTrait:: |
public | function | 1 | |
DependencySerializationTrait:: |
public | function | 2 | |
EdgeEntityDisplaySettingsForm:: |
protected | property | The entity display repository. | |
EdgeEntityDisplaySettingsForm:: |
protected | property | The entity type ID. | |
EdgeEntityDisplaySettingsForm:: |
protected | property | The entity type manager. | |
EdgeEntityDisplaySettingsForm:: |
protected | property | The module handler. | |
EdgeEntityDisplaySettingsForm:: |
protected | property |
The route match. Overrides FormBase:: |
|
EdgeEntityDisplaySettingsForm:: |
public | function |
Form constructor. Overrides ConfigFormBase:: |
|
EdgeEntityDisplaySettingsForm:: |
public static | function |
Instantiates a new instance of this class. Overrides ConfigFormBase:: |
|
EdgeEntityDisplaySettingsForm:: |
public | function |
Returns a string identifying the base form. Overrides BaseFormIdInterface:: |
|
EdgeEntityDisplaySettingsForm:: |
protected | function |
Gets the configuration names that will be editable. Overrides ConfigFormBaseTrait:: |
|
EdgeEntityDisplaySettingsForm:: |
public | function |
Returns a unique string identifying the form. Overrides FormInterface:: |
|
EdgeEntityDisplaySettingsForm:: |
public | function |
Form submission handler. Overrides ConfigFormBase:: |
|
EdgeEntityDisplaySettingsForm:: |
public | function |
AppDisplaySettingsForm constructor. Overrides ConfigFormBase:: |
|
FormBase:: |
protected | property | The config factory. | 1 |
FormBase:: |
protected | property | The request stack. | 1 |
FormBase:: |
protected | function | Gets the config factory for this form. | 1 |
FormBase:: |
private | function | Returns the service container. | |
FormBase:: |
protected | function | Gets the current user. | |
FormBase:: |
protected | function | Gets the request object. | |
FormBase:: |
protected | function | Gets the route match. | |
FormBase:: |
protected | function | Gets the logger for a specific channel. | |
FormBase:: |
protected | function |
Returns a redirect response object for the specified route. Overrides UrlGeneratorTrait:: |
|
FormBase:: |
public | function | Resets the configuration factory. | |
FormBase:: |
public | function | Sets the config factory for this form. | |
FormBase:: |
public | function | Sets the request stack object to use. | |
FormBase:: |
public | function |
Form validation handler. Overrides FormInterface:: |
62 |
LinkGeneratorTrait:: |
protected | property | The link generator. | 1 |
LinkGeneratorTrait:: |
protected | function | Returns the link generator. | |
LinkGeneratorTrait:: |
protected | function | Renders a link to a route given a route name and its parameters. | |
LinkGeneratorTrait:: |
public | function | Sets the link generator service. | |
LoggerChannelTrait:: |
protected | property | The logger channel factory service. | |
LoggerChannelTrait:: |
protected | function | Gets the logger for a specific channel. | |
LoggerChannelTrait:: |
public | function | Injects the logger channel factory. | |
MessengerTrait:: |
protected | property | The messenger. | 29 |
MessengerTrait:: |
public | function | Gets the messenger. | 29 |
MessengerTrait:: |
public | function | Sets the messenger. | |
RedirectDestinationTrait:: |
protected | property | The redirect destination service. | 1 |
RedirectDestinationTrait:: |
protected | function | Prepares a 'destination' URL query parameter for use with \Drupal\Core\Url. | |
RedirectDestinationTrait:: |
protected | function | Returns the redirect destination service. | |
RedirectDestinationTrait:: |
public | function | Sets the redirect destination service. | |
StringTranslationTrait:: |
protected | property | The string translation service. | 1 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. | |
UrlGeneratorTrait:: |
protected | property | The url generator. | |
UrlGeneratorTrait:: |
protected | function | Returns the URL generator service. | |
UrlGeneratorTrait:: |
public | function | Sets the URL generator service. | |
UrlGeneratorTrait:: |
protected | function | Generates a URL or path for a specific route based on the given parameters. |