Skip to content
Snippets Groups Projects
Commit f69f5e45 authored by Omkar Deshpande's avatar Omkar Deshpande Committed by mandclu
Browse files

git commit -m 'Issue #3299757 by omkar-pd, anoopsingh92, akshaydalvi212,...

git commit -m 'Issue #3299757 by omkar-pd, anoopsingh92, akshaydalvi212, mandclu: Drupal Coding Standard issues'
parent 3d74a531
No related branches found
No related tags found
1 merge request!2php cbf
......@@ -22,14 +22,14 @@ function date_augmenter_field_formatter_third_party_settings_form($plugin, $fiel
// Make sure the service is available.
$dateAugmenterManager = \Drupal::service('plugin.manager.dateaugmenter');
if (!$dateAugmenterManager) {
// TODO: throw an error here?
// @todo throw an error here?
return;
}
$augmenters = $dateAugmenterManager->getDefinitions();
// Retrieve configuration.
if ($field_definition instanceof BaseFieldDefinition) {
// TODO: populaate $config for custom entities.
// @todo populaate $config for custom entities.
$config = $field_definition->getSetting('augmenters');
}
else {
......@@ -61,101 +61,104 @@ function date_augmenter_field_formatter_third_party_settings_form($plugin, $fiel
return $element;
}
/**
* Adds status weights augmenter_settings configuration fields.
*/
function date_augmenter_make_config_fields($config, $augmenters, $dateAugmenterManager, $field_definition) {
$active_augmenters = $config['status'] ?? [];
$active_augmenters = $config['status'] ?? [];
// Add the list of augmenters with checkboxes to enable/disable them.
$element['status'] = [
'#type' => 'fieldset',
'#title' => t('Enabled Date Augmenters'),
// Add the list of augmenters with checkboxes to enable/disable them.
$element['status'] = [
'#type' => 'fieldset',
'#title' => t('Enabled Date Augmenters'),
'#attributes' => [
'class' => [
'date-augmenter-status-wrapper',
],
],
];
foreach ($augmenters as $augmenter_id => $augmenter) {
$clean_css_id = Html::cleanCssIdentifier($augmenter_id);
$is_enabled = !empty($active_augmenters[$augmenter_id]);
$element['status'][$augmenter_id] = [
'#type' => 'checkbox',
'#title' => $augmenter['label'],
'#default_value' => $is_enabled,
'#description' => $augmenter['description'],
'#attributes' => [
'class' => [
'date-augmenter-status-wrapper',
'date-augmenter-status-' . $clean_css_id,
],
'data-id' => $clean_css_id,
],
];
foreach ($augmenters as $augmenter_id => $augmenter) {
$clean_css_id = Html::cleanCssIdentifier($augmenter_id);
$is_enabled = !empty($active_augmenters[$augmenter_id]);
$element['status'][$augmenter_id] = [
'#type' => 'checkbox',
'#title' => $augmenter['label'],
'#default_value' => $is_enabled,
'#description' => $augmenter['description'],
'#attributes' => [
'class' => [
'date-augmenter-status-' . $clean_css_id,
],
'data-id' => $clean_css_id,
],
];
}
}
$element['weights'] = [
'#type' => 'fieldset',
'#title' => t('Augmenting order'),
];
$element['weights']['order'] = [
'#type' => 'table',
];
$element['weights']['order']['#tabledrag'][] = [
'action' => 'order',
'relationship' => 'sibling',
'group' => 'date-augmenter-weight',
$element['weights'] = [
'#type' => 'fieldset',
'#title' => t('Augmenting order'),
];
$element['weights']['order'] = [
'#type' => 'table',
];
$element['weights']['order']['#tabledrag'][] = [
'action' => 'order',
'relationship' => 'sibling',
'group' => 'date-augmenter-weight',
];
$augmenter_weights = [];
foreach ($augmenters as $augmenter_id => $augmenter) {
$augmenter_weights[$augmenter_id] = $config['weights']['order'][$augmenter_id]['weight'] ?? 0;
}
asort($augmenter_weights);
foreach ($augmenter_weights as $augmenter_id => $weight) {
$augmenter = $augmenters[$augmenter_id];
$element['weights']['order'][$augmenter_id]['#attributes']['class'][] = 'draggable';
$element['weights']['order'][$augmenter_id]['#attributes']['class'][] = 'date-augmenter-weight--' . Html::cleanCssIdentifier($augmenter_id);
$element['weights']['order'][$augmenter_id]['#weight'] = $weight;
$element['weights']['order'][$augmenter_id]['label']['#plain_text'] = $augmenter['label'];
$element['weights']['order'][$augmenter_id]['weight'] = [
'#type' => 'weight',
'#title' => t('Weight for augmenter %title', ['%title' => $augmenter['label']]),
'#title_display' => 'invisible',
'#delta' => 50,
'#default_value' => $weight,
'#attributes' => [
'class' => [
'date-augmenter-weight',
],
],
];
$augmenter_weights = [];
foreach ($augmenters as $augmenter_id => $augmenter) {
$augmenter_weights[$augmenter_id] = $config['weights']['order'][$augmenter_id]['weight'] ?? 0;
}
asort($augmenter_weights);
}
foreach ($augmenter_weights as $augmenter_id => $weight) {
$augmenter = $augmenters[$augmenter_id];
$element['weights']['order'][$augmenter_id]['#attributes']['class'][] = 'draggable';
$element['weights']['order'][$augmenter_id]['#attributes']['class'][] = 'date-augmenter-weight--' . Html::cleanCssIdentifier($augmenter_id);
$element['weights']['order'][$augmenter_id]['#weight'] = $weight;
$element['weights']['order'][$augmenter_id]['label']['#plain_text'] = $augmenter['label'];
$element['weights']['order'][$augmenter_id]['weight'] = [
'#type' => 'weight',
'#title' => t('Weight for augmenter %title', ['%title' => $augmenter['label']]),
'#title_display' => 'invisible',
'#delta' => 50,
'#default_value' => $weight,
// Add vertical tabs containing the settings for the augmenters. Tabs for
// disabled augmenters are hidden with JS magic, but need to be included in
// case the augmenter is enabled.
$element['augmenter_settings'] = [
'#title' => t('Augmenter settings'),
'#type' => 'vertical_tabs',
];
foreach ($augmenters as $augmenter_id => $augmenter) {
$aug_plugin = $dateAugmenterManager->createInstance($augmenter_id);
if ($aug_plugin instanceof PluginFormInterface) {
$element['settings'][$augmenter_id] = [
'#type' => 'details',
'#title' => $augmenter['label'],
'#group' => 'augmenter_settings',
'#attributes' => [
'class' => [
'date-augmenter-weight',
'date-augmenter-settings-' . Html::cleanCssIdentifier($augmenter_id),
],
],
];
$settings = $config['settings'][$augmenter_id] ?? [];
$element['settings'][$augmenter_id] += $aug_plugin->configurationFields($element['settings'][$augmenter_id], $settings, $field_definition);
}
// Add vertical tabs containing the settings for the augmenters. Tabs for
// disabled augmenters are hidden with JS magic, but need to be included in
// case the augmenter is enabled.
$element['augmenter_settings'] = [
'#title' => t('Augmenter settings'),
'#type' => 'vertical_tabs',
];
foreach ($augmenters as $augmenter_id => $augmenter) {
$aug_plugin = $dateAugmenterManager->createInstance($augmenter_id);
if ($aug_plugin instanceof PluginFormInterface) {
$element['settings'][$augmenter_id] = [
'#type' => 'details',
'#title' => $augmenter['label'],
'#group' => 'augmenter_settings',
'#attributes' => [
'class' => [
'date-augmenter-settings-' . Html::cleanCssIdentifier($augmenter_id),
],
],
];
$settings = $config['settings'][$augmenter_id] ?? [];
$element['settings'][$augmenter_id] += $aug_plugin->configurationFields($element['settings'][$augmenter_id], $settings, $field_definition);
}
else {
unset($element['settings'][$augmenter_id]);
}
else {
unset($element['settings'][$augmenter_id]);
}
}
return $element;
}
......@@ -13,7 +13,7 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
* need it, for example to have access to one of the following:
* - \Drupal\Component\Plugin\PluginInspectionInterface
* - \Drupal\Core\Extension\ModuleHandlerInterface
* - \Drupal\Core\Extension\ThemeHandlerInterface
* - \Drupal\Core\Extension\ThemeHandlerInterface.
*
* @see https://www.drupal.org/node/3099004.
*/
......
......@@ -13,8 +13,23 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
abstract class DateAugmenterBase extends PluginBase implements DateAugmenterInterface {
use StringTranslationTrait;
/**
* The date augmenter process Service.
*
* @var array
*/
protected $processService;
/**
* The date augmenter configuration.
*
* @var array
*/
protected $config;
/**
* {@inheritdoc}
*/
protected $output;
/**
......
......@@ -39,13 +39,16 @@ class DateAugmenterManager extends DefaultPluginManager {
/**
* Create an array of the enabled plugins.
*
* @param array|null $active_augmenters
* @param array $config
* The configuration of the date augmenter.
*
* @var array|null $active_augmenters
* The configrued plugins.
*
* @return array
* A keyed array of instantiated plugins.
*/
public function getActivePlugins(?array $config) {
public function getActivePlugins(array $config) {
if (!$config || empty($config['status'])) {
return [];
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment