You are here

public function InstagramPostBlock::blockForm in Social Feed 8

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 SocialBlockBase::blockForm

File

src/Plugin/Block/InstagramPostBlock.php, line 83

Class

InstagramPostBlock
Provides a 'InstagramPostBlock' block.

Namespace

Drupal\socialfeed\Plugin\Block

Code

public function blockForm($form, FormStateInterface $form_state) {
  $form = parent::blockForm($form, $form_state);
  $this
    ->messenger()
    ->addWarning($this
    ->t('By overriding the `FEED CONFIGURATION` settings here, this block won\'t receive the renewed <strong>Access Token</strong> when the current one expires in <strong>60 days</strong>, hence you have to manually add a new <strong>Access Token</strong> post expiry. <br /> Global Settings doesn\'t have this limitation so in case if you haven\'t configured them here yet, then you should configure the `FEED CONFIGURATION` at <a href="@admin">/admin/config/socialfeed/instagram</a>', [
    '@admin' => Url::fromRoute('socialfeed.instagram_settings_form')
      ->toString(),
  ]));
  $form['overrides']['client_id'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('App ID'),
    '#description' => $this
      ->t('App ID from Instagram account'),
    '#default_value' => $this
      ->defaultSettingValue('client_id'),
    '#size' => 60,
    '#maxlength' => 100,
    '#required' => TRUE,
  ];
  $form['overrides']['app_secret'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('App Secret'),
    '#description' => $this
      ->t('App Secret from Instagram account'),
    '#default_value' => $this
      ->defaultSettingValue('app_secret'),
    '#size' => 60,
    '#maxlength' => 100,
    '#required' => TRUE,
  ];
  $form['overrides']['redirect_uri'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Redirect URI'),
    '#description' => $this
      ->t('Redirect Uri added to Instagram account'),
    '#default_value' => $this
      ->defaultSettingValue('redirect_uri'),
    '#size' => 60,
    '#maxlength' => 100,
    '#required' => TRUE,
  ];
  $form['overrides']['access_token'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Access Token'),
    '#description' => $this
      ->t('This access token will need to be renewed every 60 days in order to continue working. You can create an access token through the <a href="https://developers.facebook.com/docs/instagram-basic-display-api/overview#user-token-generator" target="_blank">Token Generator</a>'),
    '#default_value' => $this
      ->defaultSettingValue('access_token'),
    '#size' => 60,
    '#maxlength' => 300,
    '#required' => TRUE,
  ];
  $form['overrides']['picture_count'] = [
    '#type' => 'number',
    '#title' => $this
      ->t('Picture Count'),
    '#default_value' => $this
      ->defaultSettingValue('picture_count'),
    '#size' => 60,
    '#maxlength' => 100,
    '#min' => 1,
  ];
  $this
    ->blockFormElementStates($form);
  $form['overrides']['post_link'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Show post URL'),
    '#default_value' => $this
      ->defaultSettingValue('post_link'),
  ];
  $form['overrides']['video_thumbnail'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Show video thumbnails instead of actual videos'),
    '#default_value' => $this
      ->defaultSettingValue('video_thumbnail'),
  ];
  return $form;
}