tarte_au_citron-1.0.0-beta1/src/Plugin/tarte_au_citron/TarteAuCitron.php
src/Plugin/tarte_au_citron/TarteAuCitron.php
<?php
namespace Drupal\tarte_au_citron\Plugin\tarte_au_citron;
use Drupal\Core\Form\FormStateInterface;
use Drupal\tarte_au_citron\ServicePluginBase;
/**
* A TarteAuCitron service plugin.
*
* @TarteAuCitronService(
* id = "tarte_au_citron",
* deriver = "Drupal\tarte_au_citron\Plugin\Derivative\TarteAuCitronServiceDeriver",
* )
*/
class TarteAuCitron extends ServicePluginBase {
/**
* {@inheritdoc}
*/
public function settingsForm(array $form, FormStateInterface $form_state): array {
$defs = $this->getPluginDefinition();
if (empty($defs['settings'])) {
return [];
}
$elements = parent::settingsForm($form, $form_state);
foreach ($defs['settings'] as $currentSetting) {
$elements['intro'] = [
'#theme' => 'tarte_au_citron_plugin_config',
];
if (preg_match('/More$/i', $currentSetting)) {
$elements[$currentSetting] = [
'#type' => 'markup',
'#markup' => $this->t(
'<p>You must implement the hook "hook_tarte_au_citron_@pluginId_alter" in a module and add a js file to define the function "tarteaucitron.user.@functionName"</p>',
[
'@pluginId' => $this->getPluginId(),
'@functionName' => $currentSetting,
]
),
];
}
else {
$elements[$currentSetting] = [
'#type' => 'textfield',
'#title' => $currentSetting,
'#default_value' => $this->getSetting($currentSetting) ?? '',
];
}
}
return $elements;
}
}
