function BlockContentDevelGenerate::settingsForm

Overrides DevelGenerateBase::settingsForm

File

devel_generate/src/Plugin/DevelGenerate/BlockContentDevelGenerate.php, line 88

Class

BlockContentDevelGenerate
Provides a BlockContentDevelGenerate plugin.

Namespace

Drupal\devel_generate\Plugin\DevelGenerate

Code

public function settingsForm(array $form, FormStateInterface $form_state) : array {
    
    /** @var \Drupal\block_content\BlockContentTypeInterface[] $blockTypes */
    $blockTypes = $this->blockContentTypeStorage
        ->loadMultiple();
    $options = [];
    foreach ($blockTypes as $type) {
        $options[$type->id()] = [
            'type' => [
                'label' => $type->label(),
                'description' => $type->getDescription(),
            ],
        ];
    }
    $header = [
        'type' => $this->t('Block Content type'),
        'description' => $this->t('Description'),
    ];
    $form['block_types'] = [
        '#type' => 'tableselect',
        '#header' => $header,
        '#options' => $options,
    ];
    $form['kill'] = [
        '#type' => 'checkbox',
        '#title' => $this->t('<strong>Delete all content</strong> in these block types before generating new content.'),
        '#default_value' => $this->getSetting('kill'),
    ];
    $form['num'] = [
        '#type' => 'number',
        '#title' => $this->t('How many blocks would you like to generate?'),
        '#default_value' => $this->getSetting('num'),
        '#required' => TRUE,
        '#min' => 0,
    ];
    $form['title_length'] = [
        '#type' => 'number',
        '#title' => $this->t('Maximum number of words in block descriptions'),
        '#default_value' => $this->getSetting('title_length'),
        '#required' => TRUE,
        '#min' => 1,
        '#max' => 255,
    ];
    $form['skip_fields'] = [
        '#type' => 'textfield',
        '#title' => $this->t('Fields to leave empty'),
        '#description' => $this->t('Enter the field names as a comma-separated list. These will be skipped and have a default value in the generated content.'),
        '#default_value' => NULL,
    ];
    $form['base_fields'] = [
        '#type' => 'textfield',
        '#title' => $this->t('Base fields to populate'),
        '#description' => $this->t('Enter the field names as a comma-separated list. These will be populated.'),
        '#default_value' => NULL,
    ];
    $form['reusable'] = [
        '#type' => 'checkbox',
        '#title' => $this->t('Reusable blocks'),
        '#description' => $this->t('This will mark the blocks to be created as reusable.'),
        '#default_value' => $this->getSetting('reusable'),
    ];
    $form['add_type_label'] = [
        '#type' => 'checkbox',
        '#title' => $this->t('Prefix the title with the block type label.'),
        '#description' => $this->t('This will not count against the maximum number of title words specified above.'),
        '#default_value' => $this->getSetting('add_type_label'),
    ];
    // Add the language and translation options.
    $form += $this->getLanguageForm('blocks');
    return $form;
}