You are here

public function SimplePopupBlocksEditForm::buildForm in Simple Popup Blocks 8.2

Same name and namespace in other branches
  1. 8 src/Form/SimplePopupBlocksEditForm.php \Drupal\simple_popup_blocks\Form\SimplePopupBlocksEditForm::buildForm()

Form constructor.

Parameters

array $form: An associative array containing the structure of the form.

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

Return value

array The form structure.

Overrides SimplePopupBlocksAddForm::buildForm

File

src/Form/SimplePopupBlocksEditForm.php, line 31

Class

SimplePopupBlocksEditForm
Form to add a database entry, with all the interesting fields.

Namespace

Drupal\simple_popup_blocks\Form

Code

public function buildForm(array $form, FormStateInterface $form_state, $uid = NULL) {
  $configFactory = \Drupal::service('config.factory');
  $data = $configFactory
    ->get('simple_popup_blocks.popup_' . $uid);
  $form = parent::buildForm($form, $form_state);
  $form['status'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Enable this as popup.'),
    '#default_value' => $data
      ->get('status'),
    '#weight' => -99,
  ];
  $visit_counts = unserialize($data
    ->get('visit_counts'));
  $identifier = $data
    ->get('identifier');
  $form['uid']['#default_value'] = $data
    ->get('uid');
  $form['uid']['#disabled'] = TRUE;
  $form['type']['#default_value'] = $data
    ->get('type');
  $form['block_list']['#default_value'] = $identifier;
  $form['custom_css']['#default_value'] = $identifier;
  $form['css_selector']['#default_value'] = $data
    ->get('css_selector');
  $form['layout']['#default_value'] = $data
    ->get('layout');
  $form['minimize']['#default_value'] = $data
    ->get('minimize');
  $form['close']['#default_value'] = $data
    ->get('close');
  $form['enable_escape']['#default_value'] = $data
    ->get('enable_escape');
  $form['overlay']['#default_value'] = $data
    ->get('overlay');
  $form['trigger_method']['#default_value'] = $data
    ->get('trigger_method');
  $form['trigger_selector']['#default_value'] = $data
    ->get('trigger_selector');
  $form['delay']['#default_value'] = $data
    ->get('delay');
  $form['trigger_width']['#default_value'] = $data
    ->get('trigger_width');
  $form['width']['#default_value'] = $data
    ->get('width');
  $form['cookie_expiry']['#default_value'] = $data
    ->get('cookie_expiry');
  $form['button_configuration']['show_minimized_button']['#default_value'] = $data
    ->get('show_minimized_button');
  $form['popup_frequency']['use_time_frequency']['#default_value'] = $data
    ->get('use_time_frequency');
  $form['popup_frequency']['time_frequency']['#default_value'] = $data
    ->get('time_frequency');
  $form['popup_frequency']['visit_counts']['#default_value'] = $visit_counts;
  $block_id_append = '';
  if ($data
    ->get('type') == 0) {
    $block_id_append = 'block-';
    $identifier = preg_replace('/[_]+/', '-', $identifier);
  }
  $identifier = $block_id_append . $identifier;
  $parent = "#spb-" . $identifier;
  $modal_class = "." . $identifier . "-modal";
  $modal_close_class = "." . $identifier . "-modal-close";
  $modal_minimize_class = "." . $identifier . "-modal-minimize";
  $modal_minimized_class = "." . $identifier . "-modal-minimized";
  $positions = [
    0 => $this
      ->t('spb_top_left'),
    1 => $this
      ->t('spb_top_right'),
    2 => $this
      ->t('spb_bottom_left'),
    3 => $this
      ->t('spb_bottom_right'),
    4 => $this
      ->t('spb_center'),
    5 => $this
      ->t('spb_top_center'),
    6 => $this
      ->t('spb_top_bar'),
    7 => $this
      ->t('spb_bottom_bar'),
    8 => $this
      ->t('spb_left_bar'),
    9 => $this
      ->t('spb_right_bar'),
  ];
  $override_positions = $modal_class . ' .' . $positions[$data
    ->get('layout')];
  $css_selector = '#';
  if ($data
    ->get('type') && $data
    ->get('css_selector') == 0) {
    $css_selector = '.';
  }
  $form['adjustments']['#description'] = $this
    ->t('Use the following css selectors to customize the popup designs.');
  $rows = [
    [
      'Parent',
      $parent,
    ],
    [
      'Identifier',
      $css_selector . $identifier,
    ],
    [
      'Modal class',
      $modal_class,
    ],
    [
      'Modal close class',
      $modal_close_class,
    ],
    [
      'Modal minimize class',
      $modal_minimize_class,
    ],
    [
      'Modal minimized class',
      $modal_minimized_class,
    ],
    [
      'Override positions',
      $override_positions,
    ],
  ];
  $form['adjustments']['table'] = [
    '#type' => 'table',
    '#rows' => $rows,
    '#empty' => t('No results found'),
  ];
  $documentation = Url::fromUri('https://www.drupal.org/docs/8/modules/simple-popup-blocks');
  $documentation = Link::fromTextAndUrl($this
    ->t('here'), $documentation);
  $documentation = $documentation
    ->toRenderable();
  $documentation = render($documentation);
  $display_none = "<p><h3>Add this css code in your css file (Recommended)</h3><p>";
  $display_none .= "<code>\n      " . $css_selector . $identifier . " {<br>\n      &nbsp;&nbsp;display: none;<br>\n      }</code><br>";
  $display_none .= "<p>While page loading with slow internet connection, content of popup will be visible to users. So you should add this css code in your theme or any css file.</p>";
  $display_none .= "<p>See the documentation " . $documentation . "</p>";
  $form['adjustments']['display_none'] = [
    '#markup' => $display_none,
  ];
  return $form;
}