You are here

public function CustomSearchBlock::blockSubmit in Custom Search 8

Overrides \Drupal\block\BlockBase::blockSubmit().

Overrides BlockPluginTrait::blockSubmit

File

src/Plugin/Block/CustomSearchBlock.php, line 888

Class

CustomSearchBlock
Provides a 'Custom Search form' block.

Namespace

Drupal\custom_search\Plugin\Block

Code

public function blockSubmit($form, FormStateInterface $form_state) {
  $this->configuration['search_box'] = [
    'label_visibility' => $form_state
      ->getValue([
      'search_box',
      'label_visibility',
    ]),
    'label' => $form_state
      ->getValue([
      'search_box',
      'label',
    ]),
    'placeholder' => $form_state
      ->getValue([
      'search_box',
      'placeholder',
    ]),
    'title' => $form_state
      ->getValue([
      'search_box',
      'title',
    ]),
    'size' => $form_state
      ->getValue([
      'search_box',
      'size',
    ]),
    'max_length' => $form_state
      ->getValue([
      'search_box',
      'max_length',
    ]),
    'weight' => $form_state
      ->getValue([
      'order',
      'table',
      'search_box',
      'weight',
    ]),
    'region' => $form_state
      ->getValue([
      'order',
      'table',
      'search_box',
      'region',
    ]),
  ];
  $this->configuration['submit'] = [
    'text' => $form_state
      ->getValue([
      'submit',
      'text',
    ]),
    'weight' => $form_state
      ->getValue([
      'order',
      'table',
      'submit',
      'weight',
    ]),
    'region' => $form_state
      ->getValue([
      'order',
      'table',
      'submit',
      'region',
    ]),
  ];

  // If the user uploaded a new submit image, save it to a permanent location.
  if ($this->moduleHandler
    ->moduleExists('file')) {

    // If the user entered a path relative to the system files directory for
    // the submit image, store a public:// URI so the theme system can handle
    // it.
    if (!$form_state
      ->isValueEmpty([
      'submit',
      'image_path',
    ])) {
      $this->configuration['submit']['image_path'] = $this
        ->validatePath($form_state
        ->getValue([
        'submit',
        'image_path',
      ]));
    }
  }
  $this->configuration['content'] = [
    'page' => $form_state
      ->getValue([
      'content',
      'page',
    ]),
    'types' => $form_state
      ->getValue([
      'content',
      'types',
    ]),
    'other' => $form_state
      ->getValue([
      'content',
      'other',
    ]),
    'selector' => [
      'type' => $form_state
        ->getValue([
        'content',
        'selector',
        'type',
      ]),
      'label_visibility' => $form_state
        ->getValue([
        'content',
        'selector',
        'label_visibility',
      ]),
      'label' => $form_state
        ->getValue([
        'content',
        'selector',
        'label',
      ]),
    ],
    'any' => [
      'text' => $form_state
        ->getValue([
        'content',
        'any',
        'text',
      ]),
      'restricts' => $form_state
        ->getValue([
        'content',
        'any',
        'restricts',
      ]),
      'force' => $form_state
        ->getValue([
        'content',
        'any',
        'force',
      ]),
    ],
    'excluded' => $form_state
      ->getValue([
      'content',
      'excluded',
    ]),
    'weight' => $form_state
      ->getValue([
      'order',
      'table',
      'content',
      'weight',
    ]),
    'region' => $form_state
      ->getValue([
      'order',
      'table',
      'content',
      'region',
    ]),
  ];
  $vocabularies = \Drupal::entityTypeManager()
    ->getStorage('taxonomy_vocabulary')
    ->loadMultiple();
  if (count($vocabularies)) {
    foreach ($vocabularies as $voc) {
      $vocId = $voc
        ->id();
      $this->configuration['taxonomy'][$vocId] = [
        'type' => $form_state
          ->getValue([
          'taxonomy',
          $vocId,
          'type',
        ]),
        'depth' => $form_state
          ->getValue([
          'taxonomy',
          $vocId,
          'depth',
        ]),
        'label_visibility' => $form_state
          ->getValue([
          'taxonomy',
          $vocId,
          'label_visibility',
        ]),
        'label' => $form_state
          ->getValue([
          'taxonomy',
          $vocId,
          'label',
        ]),
        'all_text' => $form_state
          ->getValue([
          'taxonomy',
          $vocId,
          'all_text',
        ]),
        'weight' => $form_state
          ->getValue([
          'order',
          'table',
          'voc-' . $vocId,
          'weight',
        ]),
        'region' => $form_state
          ->getValue([
          'order',
          'table',
          'voc-' . $vocId,
          'region',
        ]),
      ];
    }
  }
  $this->configuration['criteria'] = [
    'or' => [
      'display' => $form_state
        ->getValue([
        'criteria',
        'or',
        'display',
      ]),
      'label' => $form_state
        ->getValue([
        'criteria',
        'or',
        'label',
      ]),
      'weight' => $form_state
        ->getValue([
        'order',
        'table',
        'or',
        'weight',
      ]),
      'region' => $form_state
        ->getValue([
        'order',
        'table',
        'or',
        'region',
      ]),
    ],
    'phrase' => [
      'display' => $form_state
        ->getValue([
        'criteria',
        'phrase',
        'display',
      ]),
      'label' => $form_state
        ->getValue([
        'criteria',
        'phrase',
        'label',
      ]),
      'weight' => $form_state
        ->getValue([
        'order',
        'table',
        'phrase',
        'weight',
      ]),
      'region' => $form_state
        ->getValue([
        'order',
        'table',
        'phrase',
        'region',
      ]),
    ],
    'negative' => [
      'display' => $form_state
        ->getValue([
        'criteria',
        'negative',
        'display',
      ]),
      'label' => $form_state
        ->getValue([
        'criteria',
        'negative',
        'label',
      ]),
      'weight' => $form_state
        ->getValue([
        'order',
        'table',
        'negative',
        'weight',
      ]),
      'region' => $form_state
        ->getValue([
        'order',
        'table',
        'negative',
        'region',
      ]),
    ],
  ];
  if ($this->moduleHandler
    ->moduleExists('search_api_page')) {
    $this->configuration['searchapi']['page'] = $form_state
      ->getValue([
      'searchapi',
      'page',
    ]);
  }
  $this->configuration['languages'] = [
    'languages' => $form_state
      ->getValue([
      'languages',
      'languages',
    ]),
    'selector' => [
      'type' => $form_state
        ->getValue([
        'languages',
        'selector',
        'type',
      ]),
      'label_visibility' => $form_state
        ->getValue([
        'languages',
        'selector',
        'label_visibility',
      ]),
      'label' => $form_state
        ->getValue([
        'languages',
        'selector',
        'label',
      ]),
    ],
    'any' => [
      'text' => $form_state
        ->getValue([
        'languages',
        'any',
        'text',
      ]),
      'restricts' => $form_state
        ->getValue([
        'languages',
        'any',
        'restricts',
      ]),
      'force' => $form_state
        ->getValue([
        'languages',
        'any',
        'force',
      ]),
    ],
    'weight' => $form_state
      ->getValue([
      'order',
      'table',
      'languages',
      'weight',
    ]),
    'region' => $form_state
      ->getValue([
      'order',
      'table',
      'languages',
      'region',
    ]),
  ];
  $this->configuration['paths'] = [
    'list' => $form_state
      ->getValue([
      'paths',
      'list',
    ]),
    'selector' => [
      'type' => $form_state
        ->getValue([
        'paths',
        'selector',
        'type',
      ]),
      'label_visibility' => $form_state
        ->getValue([
        'paths',
        'selector',
        'label_visibility',
      ]),
      'label' => $form_state
        ->getValue([
        'paths',
        'selector',
        'label',
      ]),
    ],
    'separator' => $form_state
      ->getValue([
      'paths',
      'separator',
    ]),
    'weight' => $form_state
      ->getValue([
      'order',
      'table',
      'paths',
      'weight',
    ]),
    'region' => $form_state
      ->getValue([
      'order',
      'table',
      'paths',
      'region',
    ]),
  ];
}