class LibraryListForm in Skinr 8.2
Provides skinr plugin installation interface.
Hierarchy
- class \Drupal\Core\Form\FormBase implements ContainerInjectionInterface, FormInterface uses DependencySerializationTrait, LoggerChannelTrait, MessengerTrait, LinkGeneratorTrait, RedirectDestinationTrait, UrlGeneratorTrait, StringTranslationTrait
- class \Drupal\Core\Form\ConfirmFormBase implements ConfirmFormInterface
- class \Drupal\skinr_ui\Form\LibraryListForm
- class \Drupal\Core\Form\ConfirmFormBase implements ConfirmFormInterface
Expanded class hierarchy of LibraryListForm
File
- skinr_ui/
src/ Form/ LibraryListForm.php, line 18 - Contains \Drupal\skinr_ui\Form\LibraryListForm.
Namespace
Drupal\skinr_ui\FormView source
class LibraryListForm extends ConfirmFormBase {
/**
* {@inheritdoc}
*/
public function getFormId() {
return 'skinr_ui_library';
}
/**
* {@inheritdoc}
*/
public function getQuestion() {
return t('Would you like to disable all skin configurations for the selected skins?');
}
/**
* {@inheritdoc}
*/
public function getCancelUrl() {
return new Url('skinr_ui.library');
}
/**
* {@inheritdoc}
*/
public function getConfirmText() {
return t('Yes');
}
/**
* {@inheritdoc}
*/
public function getCancelText() {
return t('No');
}
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state, $theme = NULL) {
$form['edited_theme'] = array(
'#type' => 'value',
'#value' => $theme,
);
$skin_infos = skinr_get_skin_info();
if (empty($skin_infos)) {
$form['skins_empty'] = array(
'#markup' => t("You don't have any skins to manage."),
);
return $form;
}
// Confirmation form.
$storage =& $form_state
->getStorage();
if (!empty($storage['sids'])) {
$form['sids'] = array(
'#theme' => 'item_list',
'#items' => array_map(function ($skin) {
return $skin['title'];
}, array_intersect_key($skin_infos, array_flip($storage['skin_infos']))),
);
// @todo Test this works properly.
return parent::buildForm($form, $form_state);
}
// Apply overridden status.
foreach ($skin_infos as $name => $skin_info) {
$skin_infos[$name]['status'] = skinr_skin_info_status_get($skin_info);
}
$groups = skinr_get_group_info();
uasort($skin_infos, array(
'\\Drupal\\Component\\Utility\\SortArray',
'sortByTitleElement',
));
$form['skin_infos'] = array(
'#tree' => TRUE,
);
// Iterate through each of the skin_infos.
foreach ($skin_infos as $name => $skin_info) {
$group = (string) $groups[$skin_info['group']]['title'];
$form['skin_infos'][$group][$name] = $this
->buildRow($skin_info, $theme);
}
// Add basic information to the fieldsets.
foreach (Element::children($form['skin_infos']) as $package) {
$form['skin_infos'][$package] += array(
'#type' => 'details',
'#title' => $this
->t($package),
'#open' => TRUE,
'#theme' => 'skinr_ui_library_details',
'#attributes' => array(
'class' => array(
'package-listing',
),
),
);
}
$form['#attached']['library'][] = 'skinr_ui/admin.styling';
$form['actions'] = array(
'#type' => 'actions',
);
$form['actions']['submit'] = array(
'#type' => 'submit',
'#value' => t('Save configuration'),
);
$form['actions']['reset'] = array(
'#type' => 'submit',
'#value' => t('Reset to defaults'),
);
return $form;
}
/**
* Build a table row for the skin info listing page.
*
* @param array $skin_info
* The list of existing skin info.
* @param $extra
* @param $theme
*
* @return array
* The form row for the given module.
*/
protected function buildRow($skin_info, $theme) {
// Grab source info.
$info = system_get_info($skin_info['source']['type'], $skin_info['source']['name']);
$source = !empty($info['name']) ? $info['name'] : $skin_info['source']['name'];
// Set the basic properties.
$row['name']['#markup'] = $skin_info['title'];
$row['description']['#markup'] = $skin_info['description'];
$row['source']['#markup'] = $this
->t('%source !type', array(
'%source' => $source,
'!type' => $skin_info['source']['type'] == 'module' ? t('module') : t('theme'),
));
$row['version']['#markup'] = $skin_info['source']['version'];
$theme_hooks = array();
foreach ($skin_info['theme hooks'] as $theme_hook) {
$theme_hooks[] = $theme_hook == '*' ? $this
->t('all hooks') : $theme_hook;
}
$row['#theme_hooks'] = $theme_hooks;
// Present a checkbox for enabling and indicating the status of a module.
$status = !empty($skin_info['status'][$theme]) ? $skin_info['status'][$theme] : 0;
$row['enable'] = array(
'#type' => 'checkbox',
'#title' => $this
->t('Enable'),
'#default_value' => (bool) $status,
'#disabled' => (bool) $status,
);
return $row;
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
$skin_infos = skinr_get_skin_info();
$theme = $form_state
->getValue('edited_theme');
$theme_info = system_get_info('theme', $theme);
$triggering_element =& $form_state
->getTriggeringElement();
$reset = $triggering_element['#id'] == 'edit-reset' ? TRUE : FALSE;
if ($reset) {
// Reset all values to their default.
foreach ($form_state
->getValue('skin_infos') as $category => $data) {
foreach ($data as $skin => $enabled) {
$default_status = isset($skin_infos[$skin]['status'][$theme]) ? $skin_infos[$skin]['status'][$theme] : $skin_infos[$skin]['default status'];
$form_state
->setValue([
'skin_infos',
$category,
$skin,
'enable',
], $default_status);
}
}
}
if ($triggering_element['#id'] == 'edit-submit' || $reset) {
// Make sure we don't disable skins for which configuration exists. Ask to
// disable all related skin configurations so we can disable the skin.
$affected_skins = array();
$disable_sids = array();
$rebuild = FALSE;
foreach ($form_state
->getValue('skin_infos') as $category => $data) {
foreach ($data as $skin => $enabled) {
$enabled = $enabled['enable'];
$status = skinr_skin_info_status_get($skin_infos[$skin]);
if (!empty($status[$theme]) && !$enabled) {
// This skin is being disabled.
$affected_skins[] = $skin;
// Find all enabled configurations for this skin.
// @todo
$params = array(
'theme' => $theme,
'skin' => $skin,
'status' => 1,
);
$sids = skinr_skin_get_sids($params);
if (count($sids)) {
$disable_sids += $sids;
$rebuild = TRUE;
}
}
}
}
if ($rebuild) {
$storage = array(
'status' => $form_state
->getValue('skin_infos'),
'skin_infos' => $affected_skins,
'sids' => $disable_sids,
'reset' => $reset,
);
$form_state
->setStorage($storage);
$form_state
->setRebuild();
drupal_set_message(t('Rebuilding skins.'));
return;
}
}
$storage =& $form_state
->getStorage();
$changed_status = array();
if (!empty($storage['sids'])) {
// Disable any configurations for skins that are being disabled.
// @todo
db_update('skinr_skins')
->fields(array(
'status' => 0,
))
->condition('sid', $storage['sids'])
->execute();
// Clear skinr_skin_load_multiple cache.
drupal_static_reset('skinr_skin_load_multiple');
foreach ($storage['skins'] as $skin) {
drupal_set_message(t('Disabled all skin configurations for skin %skin and theme %theme.', array(
'%skin' => $skin,
'%theme' => $theme_info['name'],
)));
}
$changed_status = $storage['status'];
$reset = $storage['reset'];
}
else {
$changed_status = $form_state
->getValue('skin_infos');
}
// Save new status.
foreach ($changed_status as $category => $data) {
foreach ($data as $skin => $enabled) {
$enabled = $enabled['enable'];
$status = skinr_skin_info_status_get($skin_infos[$skin]);
if (!isset($status[$theme]) || $status[$theme] != $enabled) {
// Update status.
$status[$theme] = $enabled;
skinr_skin_info_status_set($skin_infos[$skin], $status);
}
}
}
if ($reset) {
drupal_set_message(t("Statuses for %theme's skins have been reset to their defaults.", array(
'%theme' => $theme_info['name'],
)));
}
else {
drupal_set_message(t("Statuses for %theme's skins have been updated.", array(
'%theme' => $theme_info['name'],
)));
}
}
}
Members
Name![]() |
Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ConfirmFormBase:: |
public | function |
Returns additional text to display as a description. Overrides ConfirmFormInterface:: |
11 |
ConfirmFormBase:: |
public | function |
Returns the internal name used to refer to the confirmation item. Overrides ConfirmFormInterface:: |
|
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 | |
FormBase:: |
protected | property | The config factory. | 1 |
FormBase:: |
protected | property | The request stack. | 1 |
FormBase:: |
protected | property | The route match. | |
FormBase:: |
protected | function | Retrieves a configuration object. | |
FormBase:: |
protected | function | Gets the config factory for this form. | 1 |
FormBase:: |
private | function | Returns the service container. | |
FormBase:: |
public static | function |
Instantiates a new instance of this class. Overrides ContainerInjectionInterface:: |
87 |
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 |
LibraryListForm:: |
public | function |
Form constructor. Overrides ConfirmFormBase:: |
|
LibraryListForm:: |
protected | function | Build a table row for the skin info listing page. | |
LibraryListForm:: |
public | function |
Returns a caption for the link which cancels the action. Overrides ConfirmFormBase:: |
|
LibraryListForm:: |
public | function |
Returns the route to go to if the user cancels the action. Overrides ConfirmFormInterface:: |
|
LibraryListForm:: |
public | function |
Returns a caption for the button that confirms the action. Overrides ConfirmFormBase:: |
|
LibraryListForm:: |
public | function |
Returns a unique string identifying the form. Overrides FormInterface:: |
|
LibraryListForm:: |
public | function |
Returns the question to ask the user. Overrides ConfirmFormInterface:: |
|
LibraryListForm:: |
public | function |
Form submission handler. Overrides FormInterface:: |
|
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. |