public function VarnishImagePurgeConfiguration::buildForm in Varnish purger 8
Same name and namespace in other branches
- 8.2 modules/varnish_image_purge/src/Form/VarnishImagePurgeConfiguration.php \Drupal\varnish_image_purge\Form\VarnishImagePurgeConfiguration::buildForm()
Form constructor.
Parameters
array $form: An associative array containing the structure of the form.
\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.
Return value
array The form structure.
Overrides ConfigFormBase::buildForm
File
- modules/
varnish_image_purge/ src/ Form/ VarnishImagePurgeConfiguration.php, line 80
Class
- VarnishImagePurgeConfiguration
- Configure site information settings for this site.
Namespace
Drupal\varnish_image_purge\FormCode
public function buildForm(array $form, FormStateInterface $form_state) {
$config = $this
->config('varnish_image_purge.configuration');
$entity_types = $config
->get('entity_types');
$content_entity_types = [];
$entity_type_definitions = $this->entityTypeManager
->getDefinitions();
/* @var $definition \Drupal\Core\Entity\EntityTypeInterface */
foreach ($entity_type_definitions as $definition) {
if ($definition instanceof ContentEntityType) {
$content_entity_types[] = $definition;
}
}
if (empty($content_entity_types)) {
$this
->messenger()
->addStatus($this
->t('No content entities were found'));
return NULL;
}
foreach ($content_entity_types as $content_entity_type) {
$form['intro'] = [
'#markup' => t('Configure bundles of entity types that Varnish image purge should be used for, if none selected, all bundles form all entity types will be used. Just the fields of type image will be purge.'),
];
$default_value = [];
if (!is_null($entity_types) && isset($entity_types[$content_entity_type
->id()])) {
$default_value = $entity_types[$content_entity_type
->id()];
}
$form['entity_types'][$content_entity_type
->id()] = [
'#type' => 'checkboxes',
'#title' => $content_entity_type
->getLabel(),
'#multiple' => TRUE,
'#options' => $this
->getOptionsFromEntity($content_entity_type),
'#default_value' => $default_value,
];
}
return parent::buildForm($form, $form_state);
}