function IconPackManager::getExtractorPluginForms

Overrides IconPackManagerInterface::getExtractorPluginForms

File

core/lib/Drupal/Core/Theme/Icon/Plugin/IconPackManager.php, line 287

Class

IconPackManager
Defines an icon pack plugin manager to deal with icons.

Namespace

Drupal\Core\Theme\Icon\Plugin

Code

public function getExtractorPluginForms(array &$form, FormStateInterface $form_state, array $default_settings = [], array $allowed_icon_pack = [], bool $wrap_details = FALSE) : void {
    $icon_pack_definitions = $this->getDefinitions();
    if (NULL === $icon_pack_definitions) {
        return;
    }
    if (!empty($allowed_icon_pack)) {
        $icon_pack_definitions = array_intersect_key($icon_pack_definitions, $allowed_icon_pack);
    }
    $extractor_forms = $this->iconPackExtractorManager
        ->getExtractorForms($icon_pack_definitions);
    if (empty($extractor_forms)) {
        return;
    }
    foreach ($icon_pack_definitions as $pack_id => $definition) {
        // Simply skip if no settings declared in definition.
        if (count($definition['settings'] ?? []) === 0) {
            continue;
        }
        // Create the container for each extractor settings used to have the
        // extractor form.
        $form[$pack_id] = [
            '#type' => $wrap_details ? 'details' : 'container',
            '#title' => $definition['label'] ?? $pack_id,
        ];
        // Create the extractor form and set settings so we can build with values.
        $subform_state = SubformState::createForSubform($form[$pack_id], $form, $form_state);
        $subform_state->getCompleteFormState()
            ->setValue('saved_values', $default_settings[$pack_id] ?? []);
        if (is_a($extractor_forms[$pack_id], '\\Drupal\\Core\\Plugin\\PluginFormInterface')) {
            $form[$pack_id] += $extractor_forms[$pack_id]->buildConfigurationForm($form[$pack_id], $subform_state);
        }
    }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.