You are here

public function SimpleInstagramBlock::blockForm in Simple Instagram Feed Block 8.2

Same name and namespace in other branches
  1. 8.3 src/Plugin/Block/SimpleInstagramBlock.php \Drupal\simple_instagram_feed\Plugin\Block\SimpleInstagramBlock::blockForm()
  2. 8 src/Plugin/Block/SimpleInstagramBlock.php \Drupal\simple_instagram_feed\Plugin\Block\SimpleInstagramBlock::blockForm()
  3. 1.0.x src/Plugin/Block/SimpleInstagramBlock.php \Drupal\simple_instagram_feed\Plugin\Block\SimpleInstagramBlock::blockForm()

Returns the configuration form elements specific to this block plugin.

Blocks that need to add form elements to the normal block configuration form should implement this method.

Parameters

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

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

Return value

array The renderable form array representing the entire configuration form.

Overrides BlockPluginTrait::blockForm

File

src/Plugin/Block/SimpleInstagramBlock.php, line 20

Class

SimpleInstagramBlock
Provides a block with a dynamic Instagram Feed.

Namespace

Drupal\simple_instagram_feed\Plugin\Block

Code

public function blockForm($form, FormStateInterface $form_state) {
  $form = parent::blockForm($form, $form_state);
  $config = $this
    ->getConfiguration();

  /**
   * {@inheritdoc}
   */
  $form['simple_instagram_username'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Instagram username'),
    '#description' => $this
      ->t('Insert the username of the instagram account in the field above.'),
    '#default_value' => isset($config['simple_instagram_username']) ? $config['simple_instagram_username'] : 'instagram',
    '#required' => TRUE,
  ];

  /**
   * {@inheritdoc}
   */
  $form['simple_instagram_display_profile'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Display profile?'),
    '#description' => $this
      ->t('Do you wish to display the Instagram profile on this Instagram Feed?'),
    '#default_value' => isset($config['simple_instagram_display_profile']) ? $config['simple_instagram_display_profile'] : 'true',
  ];

  /**
   * {@inheritdoc}
   */
  $form['simple_instagram_display_biography'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Display bio?'),
    '#description' => $this
      ->t('Do you wish to display the Instagram Bio on this Instagram Feed?'),
    '#default_value' => isset($config['simple_instagram_display_biography']) ? $config['simple_instagram_display_biography'] : 'true',
  ];

  /**
   * {@inheritdoc}
   */
  $form['simple_instagram_items'] = [
    '#type' => 'textfield',
    '#size' => 3,
    '#maxlength' => 3,
    '#title' => $this
      ->t('Number of images'),
    '#description' => $this
      ->t('How many images do you wish to feature on this Instagram Feed?'),
    '#default_value' => isset($config['simple_instagram_items']) ? $config['simple_instagram_items'] : '12',
    '#required' => TRUE,
  ];
  $simple_items_range = range(1, 12);

  /**
   * {@inheritdoc}
   */
  $form['simple_instagram_items_per_row'] = [
    '#type' => 'select',
    '#options' => [
      $simple_items_range,
    ],
    '#title' => $this
      ->t('Number of images per row?'),
    '#description' => $this
      ->t('How many images do you wish to feature on each row of this Instagram Feed? You can produce a single row if you set the numnber of images to equal the number of images per row.'),
    '#default_value' => isset($config['simple_instagram_items_per_row']) ? $config['simple_instagram_items_per_row'] : '5',
  ];
  return $form;
}