You are here

class EdgeEntityDisplaySettingsForm in Apigee Edge 8

Configuration form for Apigee entities display settings.

Hierarchy

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\Form
View 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

Namesort descending Modifiers Type Description Overrides
ConfigFormBaseTrait::config protected function Retrieves a configuration object.
DependencySerializationTrait::$_entityStorages protected property An array of entity type IDs keyed by the property name of their storages.
DependencySerializationTrait::$_serviceIds protected property An array of service IDs keyed by property name used for serialization.
DependencySerializationTrait::__sleep public function 1
DependencySerializationTrait::__wakeup public function 2
EdgeEntityDisplaySettingsForm::$entityDisplayRepository protected property The entity display repository.
EdgeEntityDisplaySettingsForm::$entityTypeId protected property The entity type ID.
EdgeEntityDisplaySettingsForm::$entityTypeManager protected property The entity type manager.
EdgeEntityDisplaySettingsForm::$moduleHandler protected property The module handler.
EdgeEntityDisplaySettingsForm::$routeMatch protected property The route match. Overrides FormBase::$routeMatch
EdgeEntityDisplaySettingsForm::buildForm public function Form constructor. Overrides ConfigFormBase::buildForm
EdgeEntityDisplaySettingsForm::create public static function Instantiates a new instance of this class. Overrides ConfigFormBase::create
EdgeEntityDisplaySettingsForm::getBaseFormId public function Returns a string identifying the base form. Overrides BaseFormIdInterface::getBaseFormId
EdgeEntityDisplaySettingsForm::getEditableConfigNames protected function Gets the configuration names that will be editable. Overrides ConfigFormBaseTrait::getEditableConfigNames
EdgeEntityDisplaySettingsForm::getFormId public function Returns a unique string identifying the form. Overrides FormInterface::getFormId
EdgeEntityDisplaySettingsForm::submitForm public function Form submission handler. Overrides ConfigFormBase::submitForm
EdgeEntityDisplaySettingsForm::__construct public function AppDisplaySettingsForm constructor. Overrides ConfigFormBase::__construct
FormBase::$configFactory protected property The config factory. 1
FormBase::$requestStack protected property The request stack. 1
FormBase::configFactory protected function Gets the config factory for this form. 1
FormBase::container private function Returns the service container.
FormBase::currentUser protected function Gets the current user.
FormBase::getRequest protected function Gets the request object.
FormBase::getRouteMatch protected function Gets the route match.
FormBase::logger protected function Gets the logger for a specific channel.
FormBase::redirect protected function Returns a redirect response object for the specified route. Overrides UrlGeneratorTrait::redirect
FormBase::resetConfigFactory public function Resets the configuration factory.
FormBase::setConfigFactory public function Sets the config factory for this form.
FormBase::setRequestStack public function Sets the request stack object to use.
FormBase::validateForm public function Form validation handler. Overrides FormInterface::validateForm 62
LinkGeneratorTrait::$linkGenerator protected property The link generator. 1
LinkGeneratorTrait::getLinkGenerator Deprecated protected function Returns the link generator.
LinkGeneratorTrait::l Deprecated protected function Renders a link to a route given a route name and its parameters.
LinkGeneratorTrait::setLinkGenerator Deprecated public function Sets the link generator service.
LoggerChannelTrait::$loggerFactory protected property The logger channel factory service.
LoggerChannelTrait::getLogger protected function Gets the logger for a specific channel.
LoggerChannelTrait::setLoggerFactory public function Injects the logger channel factory.
MessengerTrait::$messenger protected property The messenger. 29
MessengerTrait::messenger public function Gets the messenger. 29
MessengerTrait::setMessenger public function Sets the messenger.
RedirectDestinationTrait::$redirectDestination protected property The redirect destination service. 1
RedirectDestinationTrait::getDestinationArray protected function Prepares a 'destination' URL query parameter for use with \Drupal\Core\Url.
RedirectDestinationTrait::getRedirectDestination protected function Returns the redirect destination service.
RedirectDestinationTrait::setRedirectDestination public function Sets the redirect destination service.
StringTranslationTrait::$stringTranslation protected property The string translation service. 1
StringTranslationTrait::formatPlural protected function Formats a string containing a count of items.
StringTranslationTrait::getNumberOfPlurals protected function Returns the number of plurals supported by a given language.
StringTranslationTrait::getStringTranslation protected function Gets the string translation service.
StringTranslationTrait::setStringTranslation public function Sets the string translation service to use. 2
StringTranslationTrait::t protected function Translates a string to the current language or to a given language.
UrlGeneratorTrait::$urlGenerator protected property The url generator.
UrlGeneratorTrait::getUrlGenerator Deprecated protected function Returns the URL generator service.
UrlGeneratorTrait::setUrlGenerator Deprecated public function Sets the URL generator service.
UrlGeneratorTrait::url Deprecated protected function Generates a URL or path for a specific route based on the given parameters.