You are here

function _block_styles_form_submit in Block Styles 8

Same name and namespace in other branches
  1. 2.x block_styles.module \_block_styles_form_submit()
  2. 1.x block_styles.module \_block_styles_form_submit()
1 string reference to '_block_styles_form_submit'
block_styles_form_block_form_alter in ./block_styles.module
Implements hook_form_alter() adding administration for block layouts.

File

./block_styles.module, line 121

Code

function _block_styles_form_submit(array &$form, FormStateInterface $form_state) {
  $results = $form_state
    ->getValues();
  $entity = $form_state
    ->getFormObject()
    ->getEntity();
  $block_layout_storage = \Drupal::entityTypeManager()
    ->getStorage('block_styles');
  $block_layout = $block_layout_storage
    ->load($entity
    ->id());
  if (isset($block_layout)) {
    $block_layout
      ->set('theme', $results['block_styles']['theme']);
    $block_layout
      ->set('classes', $results['block_styles']['classes']);
    $block_layout
      ->set('text', $results['block_styles']['text']);
  }
  else {
    $block_layout = \Drupal::entityManager()
      ->getStorage('block_styles')
      ->create([
      'id' => $entity
        ->id(),
      'theme' => $results['block_styles']['theme'],
      'classes' => $results['block_styles']['classes'],
      'text' => $results['block_styles']['text'],
    ]);
  }
  $status = $block_layout
    ->save();
  if ($status) {
    \Drupal::logger('block_styles')
      ->notice('Block style template was @type, for block %title to theme %theme', [
      '@type' => $status == 1 ? 'Saved' : 'Updated',
      '%title' => $entity
        ->id(),
      '%theme' => $results['block_styles']['theme'],
    ]);
  }
}