Skip to content
Permalink
Browse files

Fix codings issues for generate:plugin:condition template file (#3873)

  • Loading branch information...
LOBsTerr committed Apr 6, 2019
1 parent 22490f2 commit 098f4876036c449a9f33ced399f98ac8d4164a6c
Showing with 88 additions and 90 deletions.
  1. +88 −90 templates/module/src/Plugin/Condition/condition.php.twig
@@ -16,114 +16,112 @@ use Drupal\Core\Plugin\Context\ContextDefinition;

{% block class_declaration %}
/**
* Provides a '{{ label }}' condition to enable a condition based in module selected status.
*
* @Condition(
* id = "{{ plugin_id }}",
* label = @Translation("{{ label }}"),
* context = {
* "{{ context_id }}" = @ContextDefinition("{{ context_definition_id }}", required = {{ context_definition_required }} , label = @Translation("{{ context_definition_label }}"))
* }
* )
*
*/
* Provides a '{{ label }}' condition to enable a condition based in module selected status.
*
* @Condition(
* id = "{{ plugin_id }}",
* label = @Translation("{{ label }}"),
* context = {
* "{{ context_id }}" = @ContextDefinition("{{ context_definition_id }}", required = {{ context_definition_required }} , label = @Translation("{{ context_definition_label }}"))
* }
* )
*
*/
class {{ class_name }} extends ConditionPluginBase {% endblock %}
{% block class_methods %}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition)
{
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static(
$configuration,
$plugin_id,
$plugin_definition
$configuration,
$plugin_id,
$plugin_definition
);
}
}

/**
* Creates a new {{ class_name }} object.
*
* @param array $configuration
* The plugin configuration, i.e. an array with configuration values keyed
* by configuration option name. The special key 'context' may be used to
* initialize the defined contexts by setting it to an array of context
* values keyed by context names.
* @param string $plugin_id
* The plugin_id for the plugin instance.
* @param mixed $plugin_definition
* The plugin implementation definition.
*/
public function __construct(array $configuration, $plugin_id, $plugin_definition) {
/**
* Creates a new {{ class_name }} object.
*
* @param array $configuration
* The plugin configuration, i.e. an array with configuration values keyed
* by configuration option name. The special key 'context' may be used to
* initialize the defined contexts by setting it to an array of context
* values keyed by context names.
* @param string $plugin_id
* The plugin_id for the plugin instance.
* @param mixed $plugin_definition
* The plugin implementation definition.
*/
public function __construct(array $configuration, $plugin_id, $plugin_definition) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
}
}

/**
/**
* {@inheritdoc}
*/
public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
// Sort all modules by their names.
$modules = system_rebuild_module_data();
uasort($modules, 'system_sort_modules_by_info_name');

$options = [NULL => t('Select a module')];
foreach($modules as $module_id => $module) {
$options[$module_id] = $module->info['name'];
}

$form['module'] = [
'#type' => 'select',
'#title' => $this->t('Select a module to validate'),
'#default_value' => $this->configuration['module'],
'#options' => $options,
'#description' => $this->t('Module selected status will be use to evaluate condition.'),
];

return parent::buildConfigurationForm($form, $form_state);
}
public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
// Sort all modules by their names.
$modules = system_rebuild_module_data();
uasort($modules, 'system_sort_modules_by_info_name');

$options = [NULL => t('Select a module')];
foreach ($modules as $module_id => $module) {
$options[$module_id] = $module->info['name'];
}

$form['module'] = [
'#type' => 'select',
'#title' => $this->t('Select a module to validate'),
'#default_value' => $this->configuration['module'],
'#options' => $options,
'#description' => $this->t('Module selected status will be use to evaluate condition.'),
];

return parent::buildConfigurationForm($form, $form_state);
}

/**
* {@inheritdoc}
*/
public function submitConfigurationForm(array &$form, FormStateInterface $form_state) {
$this->configuration['module'] = $form_state->getValue('module');
parent::submitConfigurationForm($form, $form_state);
}
/**
* {@inheritdoc}
*/
public function submitConfigurationForm(array &$form, FormStateInterface $form_state) {
$this->configuration['module'] = $form_state->getValue('module');
parent::submitConfigurationForm($form, $form_state);
}

/**
* {@inheritdoc}
*/
public function defaultConfiguration() {
/**
* {@inheritdoc}
*/
public function defaultConfiguration() {
return ['module' => ''] + parent::defaultConfiguration();
}
}

/**
* Evaluates the condition and returns TRUE or FALSE accordingly.
*
* @return bool
* TRUE if the condition has been met, FALSE otherwise.
*/
/**
* Evaluates the condition and returns TRUE or FALSE accordingly.
*
* @return bool
* TRUE if the condition has been met, FALSE otherwise.
*/
public function evaluate() {
if (empty($this->configuration['module']) && !$this->isNegated()) {
return TRUE;
}
if (empty($this->configuration['module']) && !$this->isNegated()){
return TRUE;
}

$module = $this->configuration['module'];
$modules = system_rebuild_module_data();
$module = $this->configuration['module'];
$modules = system_rebuild_module_data();

return $modules[$module]->status;
return $modules[$module]->status;
}

/**
* Provides a human readable summary of the condition's configuration.
*/
public function summary()
{
$module = $this->getContextValue('module');
$modules = system_rebuild_module_data();
/**
* Provides a human readable summary of the condition's configuration.
*/
public function summary() {
$module = $this->getContextValue('module');
$modules = system_rebuild_module_data();

$status = ($modules[$module]->status)?t('enabled'):t('disabled');
$status = ($modules[$module]->status)?t('enabled'):t('disabled');

return t('The module @module is @status.', ['@module' => $module, '@status' => $status]);
}
return t('The module @module is @status.', ['@module' => $module, '@status' => $status]);
}
{% endblock %}

0 comments on commit 098f487

Please sign in to comment.
You can’t perform that action at this time.