You are here

public function HierarchicalTaxonomyMenuBlock::blockForm in Hierarchical Taxonomy Menu 8

Overrides BlockPluginTrait::blockForm

File

src/Plugin/Block/HierarchicalTaxonomyMenuBlock.php, line 181

Class

HierarchicalTaxonomyMenuBlock
Provides a 'HierarchicalTaxonomyMenuBlock' block.

Namespace

Drupal\hierarchical_taxonomy_menu\Plugin\Block

Code

public function blockForm($form, FormStateInterface $form_state) {
  $form['basic'] = [
    '#type' => 'details',
    '#title' => $this
      ->t('Basic settings'),
  ];
  $form['basic']['vocabulary'] = [
    '#title' => $this
      ->t('Use taxonomy terms from this vocabulary to create a menu'),
    '#type' => 'select',
    '#options' => $this
      ->getVocabularyOptions(),
    '#required' => TRUE,
    '#default_value' => $this->configuration['vocabulary'],
    '#description' => $this
      ->t('You can display an image next to a menu item if your vocabulary has an image field.'),
  ];
  $form['basic']['max_depth'] = [
    '#title' => $this
      ->t('Number of sublevels to display'),
    '#type' => 'select',
    '#options' => [
      '0' => '0',
      '1' => '1',
      '2' => '2',
      '3' => '3',
      '4' => '4',
      '5' => '5',
      '6' => '6',
      '7' => '7',
      '8' => '8',
      '9' => '9',
      '10' => '10',
      '100' => $this
        ->t('Unlimited'),
    ],
    '#default_value' => $this->configuration['max_depth'],
  ];
  $form['basic']['dynamic_block_title'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Make the block title match the current taxonomy term name'),
    '#default_value' => $this->configuration['dynamic_block_title'],
  ];
  $form['basic']['collapsible'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Make the menu collapsed by default'),
    '#default_value' => $this->configuration['collapsible'],
  ];
  $form['basic']['stay_open'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Stay open at the current taxonomy term'),
    '#default_value' => $this->configuration['stay_open'],
    '#states' => [
      'visible' => [
        [
          ':input[name="settings[basic][collapsible]"]' => [
            'checked' => TRUE,
          ],
        ],
      ],
    ],
  ];
  $form['basic']['interactive_parent'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Allow parent items to be collapsible and selectable'),
    '#default_value' => $this->configuration['interactive_parent'],
    '#states' => [
      'visible' => [
        [
          ':input[name="settings[basic][collapsible]"]' => [
            'checked' => TRUE,
          ],
        ],
      ],
    ],
  ];
  $form['basic']['hide_block'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Hide block if the output is empty'),
    '#default_value' => $this->configuration['hide_block'],
  ];
  $form['image'] = [
    '#type' => 'details',
    '#title' => $this
      ->t('Image settings'),
  ];
  $form['image']['notice'] = [
    '#type' => 'markup',
    '#markup' => $this
      ->t('If you are displaying an image next to menu items you can choose the size for that image. You can do that by providing the image size in pixels or by using an image style.'),
  ];
  $form['image']['use_image_style'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Use image style'),
    '#default_value' => $this->configuration['use_image_style'],
  ];
  $form['image']['image_height'] = [
    '#type' => 'number',
    '#title' => $this
      ->t('Image height (px)'),
    '#default_value' => $this->configuration['image_height'],
    '#states' => [
      'visible' => [
        [
          ':input[name="settings[image][use_image_style]"]' => [
            'checked' => FALSE,
          ],
        ],
      ],
    ],
  ];
  $form['image']['image_width'] = [
    '#type' => 'number',
    '#title' => $this
      ->t('Image width (px)'),
    '#default_value' => $this->configuration['image_width'],
    '#states' => [
      'visible' => [
        [
          ':input[name="settings[image][use_image_style]"]' => [
            'checked' => FALSE,
          ],
        ],
      ],
    ],
  ];
  $form['image']['image_style'] = [
    '#title' => $this
      ->t('Image style'),
    '#type' => 'select',
    '#options' => $this
      ->getImageStyleOptions(),
    '#default_value' => $this->configuration['image_style'],
    '#states' => [
      'visible' => [
        [
          ':input[name="settings[image][use_image_style]"]' => [
            'checked' => TRUE,
          ],
        ],
      ],
    ],
  ];
  $form['advanced'] = [
    '#type' => 'details',
    '#title' => $this
      ->t('Advanced settings'),
  ];
  $form['advanced']['max_age'] = [
    '#title' => $this
      ->t('Cache'),
    '#type' => 'select',
    '#options' => [
      '0' => $this
        ->t('No Caching'),
      '1800' => $this
        ->t('30 Minutes'),
      '3600' => $this
        ->t('1 Hour'),
      '21600' => $this
        ->t('6 Hours'),
      '43200' => $this
        ->t('12 Hours'),
      '86400' => $this
        ->t('1 Day'),
      '604800' => $this
        ->t('1 Week'),
      'PERMANENT' => $this
        ->t('Permanent'),
    ],
    '#default_value' => $this->configuration['max_age'],
    '#description' => $this
      ->t('Set the max age the menu is allowed to be cached for.'),
  ];
  $form['advanced']['base_term'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Base term'),
    '#size' => 20,
    '#default_value' => $this->configuration['base_term'],
    '#description' => $this
      ->t('Enter a base term and menu items will only be generated for its children. You can enter term ID or term name. Leave empty to generate menu for the entire vocabulary.'),
    '#states' => [
      'visible' => [
        ':input[name="settings[advanced][dynamic_base_term]"]' => [
          'checked' => FALSE,
        ],
      ],
    ],
  ];
  $form['advanced']['dynamic_base_term'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Dynamic Base term'),
    '#default_value' => $this->configuration['dynamic_base_term'],
    '#description' => $this
      ->t('Automatically set the base term from taxonomy page. The base term is then set to the current term and menu items will only be generated for its children.'),
  ];
  $form['advanced']['show_count'] = [
    '#type' => 'radios',
    '#title' => $this
      ->t('Show count of referencing entities'),
    '#options' => [
      0 => $this
        ->t('No'),
      1 => $this
        ->t('Show count of referencing nodes'),
      2 => $this
        ->t('Show count of referencing commerce products'),
    ],
    '#default_value' => $this->configuration['show_count'],
  ];
  $form['advanced']['referencing_field'] = [
    '#type' => 'select',
    '#title' => $this
      ->t('Referencing field'),
    '#options' => $this
      ->getReferencingFields(),
    '#default_value' => $this->configuration['referencing_field'],
    '#states' => [
      'visible' => [
        ':input[name="settings[advanced][show_count]"]' => [
          'value' => '2',
        ],
      ],
    ],
  ];
  $form['advanced']['calculate_count_recursively'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Calculate count recursively'),
    '#default_value' => $this->configuration['calculate_count_recursively'],
  ];
  return $form;
}