class PhotosAdminStructureForm in Album Photos 6.0.x
Same name and namespace in other branches
- 8.5 src/Form/PhotosAdminStructureForm.php \Drupal\photos\Form\PhotosAdminStructureForm
Defines a form to configure maintenance settings for this site.
Hierarchy
- class \Drupal\Core\Form\FormBase implements ContainerInjectionInterface, FormInterface uses DependencySerializationTrait, LoggerChannelTrait, MessengerTrait, RedirectDestinationTrait, StringTranslationTrait
- class \Drupal\Core\Form\ConfigFormBase uses ConfigFormBaseTrait
- class \Drupal\photos\Form\PhotosAdminStructureForm
- class \Drupal\Core\Form\ConfigFormBase uses ConfigFormBaseTrait
Expanded class hierarchy of PhotosAdminStructureForm
1 string reference to 'PhotosAdminStructureForm'
File
- src/
Form/ PhotosAdminStructureForm.php, line 17
Namespace
Drupal\photos\FormView source
class PhotosAdminStructureForm extends ConfigFormBase {
/**
* The entity display repository.
*
* @var \Drupal\Core\Entity\EntityDisplayRepositoryInterface
*/
protected $entityDisplayRepository;
/**
* The module handler.
*
* @var \Drupal\Core\Extension\ModuleHandlerInterface
*/
protected $moduleHandler;
/**
* {@inheritdoc}
*/
public function getFormId() {
return 'photos_admin_settings';
}
/**
* Constructs PhotosAdminSettingsForm.
*
* @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
* The factory for configuration objects.
* @param \Drupal\Core\Entity\EntityDisplayRepositoryInterface $entity_display_repository
* The entity display repository.
* @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
* The module handler.
*/
public function __construct(ConfigFactoryInterface $config_factory, EntityDisplayRepositoryInterface $entity_display_repository, ModuleHandlerInterface $module_handler) {
parent::__construct($config_factory);
$this->entityDisplayRepository = $entity_display_repository;
$this->moduleHandler = $module_handler;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static($container
->get('config.factory'), $container
->get('entity_display.repository'), $container
->get('module_handler'));
}
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state) {
$form = parent::buildForm($form, $form_state);
// Get variables for default values.
$config = $this
->config('photos.settings');
// Load custom admin css and js library.
$form['#attached']['library'] = [
'photos/photos.admin',
];
// Display settings.
$form['display'] = [
'#title' => $this
->t('Display'),
'#type' => 'container',
];
$form['display']['description'] = [
'#markup' => $this
->t('Default view modes. Add more custom view modes for Photo here: @display_modes_link and enable them here: @view_modes_link.', [
'@display_modes_link' => Link::fromTextAndUrl($this
->t('View modes'), Url::fromRoute('entity.entity_view_mode.collection'))
->toString(),
'@view_modes_link' => Link::fromTextAndUrl($this
->t('photos custom display settings'), Url::fromRoute('entity.entity_view_display.photos_image.default'))
->toString(),
]),
];
$viewModeOptions = $this->entityDisplayRepository
->getViewModeOptionsByBundle('photos_image', 'photos_image');
$form['display']['view_mode_rearrange_album_page'] = [
'#title' => $this
->t('Rearrange albums page'),
'#type' => 'select',
'#options' => $viewModeOptions,
'#default_value' => $config
->get('view_mode_rearrange_album_page') ?: 'sort',
];
$form['display']['view_mode_rearrange_image_page'] = [
'#title' => $this
->t('Rearrange images page'),
'#type' => 'select',
'#options' => $viewModeOptions,
'#default_value' => $config
->get('view_mode_rearrange_image_page') ?: 'sort',
];
return parent::buildForm($form, $form_state);
}
/**
* {@inheritdoc}
*/
public function validateForm(array &$form, FormStateInterface $form_state) {
// ...
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
parent::submitForm($form, $form_state);
$this
->config('photos.settings')
->set('view_mode_rearrange_album_page', $form_state
->getValue('view_mode_rearrange_album_page'))
->set('view_mode_rearrange_image_page', $form_state
->getValue('view_mode_rearrange_image_page'))
->save();
}
/**
* {@inheritdoc}
*/
protected function getEditableConfigNames() {
return [
'photos.settings',
];
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ConfigFormBaseTrait:: |
protected | function | Retrieves a configuration object. | |
DependencySerializationTrait:: |
protected | property | ||
DependencySerializationTrait:: |
protected | property | ||
DependencySerializationTrait:: |
public | function | 2 | |
DependencySerializationTrait:: |
public | function | 2 | |
FormBase:: |
protected | property | The config factory. | 3 |
FormBase:: |
protected | property | The request stack. | 1 |
FormBase:: |
protected | property | The route match. | |
FormBase:: |
protected | function | Gets the config factory for this form. | 3 |
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. | |
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. | |
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. | 27 |
MessengerTrait:: |
public | function | Gets the messenger. | 27 |
MessengerTrait:: |
public | function | Sets the messenger. | |
PhotosAdminStructureForm:: |
protected | property | The entity display repository. | |
PhotosAdminStructureForm:: |
protected | property | The module handler. | |
PhotosAdminStructureForm:: |
public | function |
Form constructor. Overrides ConfigFormBase:: |
|
PhotosAdminStructureForm:: |
public static | function |
Instantiates a new instance of this class. Overrides ConfigFormBase:: |
|
PhotosAdminStructureForm:: |
protected | function |
Gets the configuration names that will be editable. Overrides ConfigFormBaseTrait:: |
|
PhotosAdminStructureForm:: |
public | function |
Returns a unique string identifying the form. Overrides FormInterface:: |
|
PhotosAdminStructureForm:: |
public | function |
Form submission handler. Overrides ConfigFormBase:: |
|
PhotosAdminStructureForm:: |
public | function |
Form validation handler. Overrides FormBase:: |
|
PhotosAdminStructureForm:: |
public | function |
Constructs PhotosAdminSettingsForm. Overrides ConfigFormBase:: |
|
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. | 4 |
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. |