You are here

public function DibaCarousel::blockSubmit in Diba carousel slider 8

Overrides BlockPluginTrait::blockSubmit

File

src/Plugin/Block/DibaCarousel.php, line 526

Class

DibaCarousel
Provides a Diba carousel Block.

Namespace

Drupal\diba_carousel\Plugin\Block

Code

public function blockSubmit($form, FormStateInterface $form_state) {

  // Set the new configuration.
  $config = $form_state
    ->getValues();
  if (isset($config['diba_carousel_settings'])) {

    // Settings list.
    $settings = [
      'content_selection' => [
        'entity_selected',
        'content_types',
        'publishing_options',
        'skip_content_without_image',
        'order_field',
        'order_direction',
        'limit',
        'filter_by_field',
        'filter_by_field_operator',
        'filter_by_field_value',
      ],
      'styling' => [
        'carousel_style',
        'show_indicators',
        'show_controls',
        'items_by_slide',
        'data_interval',
      ],
      'slide_fields' => [
        'image',
        'image_style',
        'image_class',
        'title',
        'url',
        'description',
        'description_allow_html',
        'description_see_more_link',
        'description_truncate',
        'more_link',
        'more_link_text',
      ],
    ];
    foreach ($settings as $key => $section) {
      foreach ($section as $config_field) {
        if (isset($config['diba_carousel_settings'][$key][$config_field])) {
          $this
            ->setConfigurationValue($config_field, $config['diba_carousel_settings'][$key][$config_field]);
        }
      }
    }

    // Force diba_carousel block cache reload and refresh block output.
    Cache::invalidateTags([
      'config:block.block.diba_carousel',
    ]);
  }
}