You are here

public function SharerichBlock::blockForm in Sharerich 8

Overrides BlockPluginTrait::blockForm

File

src/Plugin/Block/SharerichBlock.php, line 25
Contains \Drupal\sharerich\Plugin\Block\SharerichBlock.

Class

SharerichBlock
Provides a Sharerich block.

Namespace

Drupal\sharerich\Plugin\Block

Code

public function blockForm($form, \Drupal\Core\Form\FormStateInterface $form_state) {
  $form = parent::blockForm($form, $form_state);
  $configuration = $this->configuration;
  $options = array();
  $entity_storage = \Drupal::entityTypeManager()
    ->getStorage('sharerich');
  foreach ($entity_storage
    ->loadMultiple() as $entity) {
    $entity_id = $entity
      ->id();
    $options[$entity_id] = $entity
      ->label();
  }
  $form['sharerich_set'] = array(
    '#type' => 'select',
    '#title' => t('Sharerich Set'),
    '#options' => $options,
    '#default_value' => isset($configuration['sharerich_set']) ? $configuration['sharerich_set'] : array(),
  );
  $form['orientation'] = array(
    '#type' => 'select',
    '#title' => t('Orientation'),
    '#options' => array(
      'horizontal' => t('Horizontal'),
      'vertical' => t('Vertical'),
    ),
    '#default_value' => isset($configuration['orientation']) ? $configuration['orientation'] : array(),
    '#description' => t('If you set to vertical and place the block on the top of the main content area, it will float on the side.'),
  );
  $form['sticky'] = array(
    '#type' => 'checkbox',
    '#title' => t('Sticky'),
    '#default_value' => isset($configuration['sticky']) ? $configuration['sticky'] : 0,
    '#description' => t('Stick to the top when scrolling.'),
    '#states' => array(
      'visible' => array(
        ':input[name="settings[orientation]"]' => array(
          'value' => 'vertical',
        ),
      ),
    ),
  );
  return $form;
}