You are here

public function FloatingMenuBlock::blockSubmit in Floating Menu 8

Adds block type-specific submission handling for the block form.

Note that this method takes the form structure and form state for the full block configuration form as arguments, not just the elements defined in BlockPluginInterface::blockForm().

Parameters

array $form: The form definition array for the full block configuration form.

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.

Overrides BlockPluginTrait::blockSubmit

See also

\Drupal\Core\Block\BlockPluginInterface::blockForm()

\Drupal\Core\Block\BlockPluginInterface::blockValidate()

File

src/Plugin/Block/FloatingMenuBlock.php, line 128

Class

FloatingMenuBlock
Provides a menu block

Namespace

Drupal\floating_menu\Plugin\Block

Code

public function blockSubmit($form, FormStateInterface $form_state) {
  $form_state_values = $form_state
    ->getValues();
  $this->configuration['count_of_items'] = $form_state_values['count_of_items'];
  $this->configuration['menu_item'] = [];
  foreach ($form_state_values['menu_items'] as $key => $value) {
    $file = File::load($value['menu_item_icon'][0]);
    if (!empty($file)) {
      $file
        ->setPermanent();
      $file
        ->save();
      $image_url = file_create_url($file
        ->getFileUri());
    }
    else {
      $image_url = NULL;
    }
    $this->configuration['menu_item'][] = [
      'menu_item_popup_html' => $value['menu_item_popup_html'],
      'menu_item_target_url' => $value['menu_item_target_url'],
      'menu_item_icon_file_id' => intval($value['menu_item_icon'][0]),
      'menu_item_icon_url' => $image_url,
    ];
  }
}