class CronPlugin in Ultimate Cron 8.2
This is the base class for all Ultimate Cron plugins.
This class handles all the load/save settings for a plugin as well as the forms, etc.
Hierarchy
- class \Drupal\Component\Plugin\PluginBase implements DerivativeInspectionInterface, PluginInspectionInterface
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait
- class \Drupal\ultimate_cron\CronPlugin implements ConfigurableInterface, DependentPluginInterface, PluginInspectionInterface, PluginFormInterface
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait
Expanded class hierarchy of CronPlugin
7 files declare their use of CronPlugin
- CronJobForm.php in src/
Form/ CronJobForm.php - LauncherBase.php in src/
Launcher/ LauncherBase.php - LoggerBase.php in src/
Logger/ LoggerBase.php - SchedulerBase.php in src/
Plugin/ ultimate_cron/ Scheduler/ SchedulerBase.php - UltimateCronCommands.php in src/
Commands/ UltimateCronCommands.php
File
- src/
CronPlugin.php, line 17
Namespace
Drupal\ultimate_cronView source
class CronPlugin extends PluginBase implements PluginInspectionInterface, ConfigurableInterface, DependentPluginInterface, PluginFormInterface {
public static $multiple = FALSE;
public static $instances = array();
public $weight = 0;
public static $globalOptions = array();
/**
* {@inheritdoc}
*/
public function __construct(array $configuration, $plugin_id, $plugin_definition) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this
->setConfiguration($configuration);
}
/**
* Returns a list of plugin types.
*
* @return array
*/
public static function getPluginTypes() {
return array(
'scheduler' => t('Scheduler'),
'launcher' => t('Launcher'),
'logger' => t('Logger'),
);
}
/**
* {@inheritdoc}
*/
public function getConfiguration() {
return $this->configuration;
}
/**
* {@inheritdoc}
*/
public function setConfiguration(array $configuration) {
$this->configuration = array_merge($this
->defaultConfiguration(), $configuration);
}
/**
* {@inheritdoc}
*/
public function defaultConfiguration() {
return array();
}
/**
* {@inheritdoc}
*/
public function calculateDependencies() {
return array();
}
/**
* {@inheritdoc}
*/
public function validateConfigurationForm(array &$form, FormStateInterface $form_state) {
}
/**
* {@inheritdoc}
*/
public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
return array();
}
/**
* {@inheritdoc}
*/
public function submitConfigurationForm(array &$form, FormStateInterface $form_state) {
}
/**
* Get global plugin option.
*
* @param string $name
* Name of global plugin option to get.
*
* @return mixed
* Value of option if any, NULL if not found.
*/
public static function getGlobalOption($name) {
return isset(static::$globalOptions[$name]) ? static::$globalOptions[$name] : NULL;
}
/**
* Get all global plugin options.
*
* @return array
* All options currently set, keyed by name.
*/
public static function getGlobalOptions() {
return static::$globalOptions;
}
/**
* Set global plugin option.
*
* @param string $name
* Name of global plugin option to get.
* @param string $value
* The value to give it.
*/
public static function setGlobalOption($name, $value) {
static::$globalOptions[$name] = $value;
}
/**
* Get label for a specific setting.
*/
public function settingsLabel($name, $value) {
if (is_array($value)) {
return implode(', ', $value);
}
else {
return $value;
}
}
/**
* Default plugin valid for all jobs.
*/
public function isValid($job = NULL) {
return TRUE;
}
/**
* Modified version drupal_array_get_nested_value().
*
* Removes the specified parents leaf from the array.
*
* @param array $array
* Nested associative array.
* @param array $parents
* Array of key names forming a "path" where the leaf will be removed
* from $array.
*/
public function drupal_array_remove_nested_value(array &$array, array $parents) {
$ref =& $array;
$last_parent = array_pop($parents);
foreach ($parents as $parent) {
if (is_array($ref) && array_key_exists($parent, $ref)) {
$ref =& $ref[$parent];
}
else {
return;
}
}
unset($ref[$last_parent]);
}
/**
* Clean form of empty fallback values.
*/
public function cleanForm($elements, &$values, $parents) {
if (empty($elements)) {
return;
}
foreach (element_children($elements) as $child) {
if (empty($child) || empty($elements[$child]) || is_numeric($child)) {
continue;
}
// Process children.
$this
->cleanForm($elements[$child], $values, $parents);
// Determine relative parents.
$rel_parents = array_diff($elements[$child]['#parents'], $parents);
$key_exists = NULL;
$value = drupal_array_get_nested_value($values, $rel_parents, $key_exists);
// Unset when applicable.
if (!empty($elements[$child]['#markup'])) {
static::drupal_array_remove_nested_value($values, $rel_parents);
}
elseif ($key_exists && empty($value) && !empty($elements[$child]['#fallback']) && $value !== '0') {
static::drupal_array_remove_nested_value($values, $rel_parents);
}
}
}
/**
* Process fallback form parameters.
*
* @param array $elements
* Elements to process.
* @param array $defaults
* Default values to add to description.
* @param bool $remove_non_fallbacks
* If TRUE, non fallback elements will be removed.
*/
public function fallbackalize(&$elements, &$values, $defaults, $remove_non_fallbacks = FALSE) {
if (empty($elements)) {
return;
}
foreach (element_children($elements) as $child) {
$element =& $elements[$child];
if (empty($element['#tree'])) {
$param_values =& $values;
$param_defaults =& $defaults;
}
else {
$param_values =& $values[$child];
$param_defaults =& $defaults[$child];
}
$this
->fallbackalize($element, $param_values, $param_defaults, $remove_non_fallbacks);
if (empty($element['#type']) || $element['#type'] == 'fieldset') {
continue;
}
if (!empty($element['#fallback'])) {
if (!$remove_non_fallbacks) {
if ($element['#type'] == 'radios') {
$label = $this
->settingsLabel($child, $defaults[$child]);
$element['#options'] = array(
'' => t('Default (@default)', array(
'@default' => $label,
)),
) + $element['#options'];
}
elseif ($element['#type'] == 'select' && empty($element['#multiple'])) {
$label = $this
->settingsLabel($child, $defaults[$child]);
$element['#options'] = array(
'' => t('Default (@default)', array(
'@default' => $label,
)),
) + $element['#options'];
}
elseif ($defaults[$child] !== '') {
$element['#description'] .= ' ' . t('(Blank = @default).', array(
'@default' => $this
->settingsLabel($child, $defaults[$child]),
));
}
unset($element['#required']);
}
}
elseif (!empty($element['#type']) && $remove_non_fallbacks) {
unset($elements[$child]);
}
elseif (!isset($element['#default_value']) || $element['#default_value'] === '') {
$empty = $element['#type'] == 'checkbox' ? FALSE : '';
$values[$child] = !empty($defaults[$child]) ? $defaults[$child] : $empty;
$element['#default_value'] = $values[$child];
}
}
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
CronPlugin:: |
public static | property | ||
CronPlugin:: |
public static | property | ||
CronPlugin:: |
public static | property | 1 | |
CronPlugin:: |
public | property | ||
CronPlugin:: |
public | function |
Form constructor. Overrides PluginFormInterface:: |
4 |
CronPlugin:: |
public | function |
Calculates dependencies for the configured plugin. Overrides DependentPluginInterface:: |
|
CronPlugin:: |
public | function | Clean form of empty fallback values. | |
CronPlugin:: |
public | function |
Gets default configuration for this plugin. Overrides ConfigurableInterface:: |
4 |
CronPlugin:: |
public | function | Modified version drupal_array_get_nested_value(). | |
CronPlugin:: |
public | function | Process fallback form parameters. | |
CronPlugin:: |
public | function |
Gets this plugin's configuration. Overrides ConfigurableInterface:: |
|
CronPlugin:: |
public static | function | Get global plugin option. | |
CronPlugin:: |
public static | function | Get all global plugin options. | |
CronPlugin:: |
public static | function | Returns a list of plugin types. | |
CronPlugin:: |
public | function | Default plugin valid for all jobs. | 1 |
CronPlugin:: |
public | function |
Sets the configuration for this plugin instance. Overrides ConfigurableInterface:: |
|
CronPlugin:: |
public static | function | Set global plugin option. | |
CronPlugin:: |
public | function | Get label for a specific setting. | 1 |
CronPlugin:: |
public | function |
Form submission handler. Overrides PluginFormInterface:: |
|
CronPlugin:: |
public | function |
Form validation handler. Overrides PluginFormInterface:: |
1 |
CronPlugin:: |
public | function |
Constructs a \Drupal\Component\Plugin\PluginBase object. Overrides PluginBase:: |
2 |
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 | |
MessengerTrait:: |
protected | property | The messenger. | 29 |
MessengerTrait:: |
public | function | Gets the messenger. | 29 |
MessengerTrait:: |
public | function | Sets the messenger. | |
PluginBase:: |
protected | property | Configuration information passed into the plugin. | 1 |
PluginBase:: |
protected | property | The plugin implementation definition. | 1 |
PluginBase:: |
protected | property | The plugin_id. | |
PluginBase:: |
constant | A string which is used to separate base plugin IDs from the derivative ID. | ||
PluginBase:: |
public | function |
Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the definition of the plugin implementation. Overrides PluginInspectionInterface:: |
3 |
PluginBase:: |
public | function |
Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface:: |
|
PluginBase:: |
public | function | Determines if the plugin is configurable. | |
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. |