public function BynderSearch::buildConfigurationForm in Bynder 8.2
Same name and namespace in other branches
- 8.3 src/Plugin/EntityBrowser/Widget/BynderSearch.php \Drupal\bynder\Plugin\EntityBrowser\Widget\BynderSearch::buildConfigurationForm()
- 8 src/Plugin/EntityBrowser/Widget/BynderSearch.php \Drupal\bynder\Plugin\EntityBrowser\Widget\BynderSearch::buildConfigurationForm()
- 4.0.x src/Plugin/EntityBrowser/Widget/BynderSearch.php \Drupal\bynder\Plugin\EntityBrowser\Widget\BynderSearch::buildConfigurationForm()
Overrides BynderWidgetBase::buildConfigurationForm
File
- src/
Plugin/ EntityBrowser/ Widget/ BynderSearch.php, line 184
Class
- BynderSearch
- Uses a Bynder API to search and provide entity listing in a browser's widget.
Namespace
Drupal\bynder\Plugin\EntityBrowser\WidgetCode
public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
$form = parent::buildConfigurationForm($form, $form_state);
$form['items_per_page'] = [
'#type' => 'select',
'#title' => $this
->t('Items per page'),
'#default_value' => $this->configuration['items_per_page'],
'#options' => [
'10' => 10,
'15' => 15,
'25' => 25,
'50' => 50,
],
];
$form['tags_filter'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Enable tags filter'),
'#default_value' => $this->configuration['tags_filter'],
];
foreach ($this->entityTypeManager
->getStorage('media_type')
->loadMultiple() as $type) {
/** @var \Drupal\media\MediaTypeInterface $type */
if ($type
->getSource() instanceof Bynder) {
$form['media_type']['#options'][$type
->id()] = $type
->label();
}
}
if (empty($form['media_type']['#options'])) {
$form['media_type']['#disabled'] = TRUE;
$form['items_per_page']['#disabled'] = TRUE;
$form['media_type']['#description'] = $this
->t('You must @create_type before using this widget.', [
'@create_type' => Link::createFromRoute($this
->t('create a Bynder media type'), 'entity.media_type.add_form')
->toString(),
]);
}
try {
$options = [];
foreach ($this->bynderApi
->getMetaproperties() as $key => $meta_property) {
if ($meta_property['isFilterable']) {
$options[$key] = bynder_get_applicable_label_translation($meta_property);
}
}
$form['allowed_properties'] = [
'#type' => 'select',
'#title' => $this
->t('Allowed metadata properties'),
'#description' => $this
->t('Select filters that should be available in the Entity Browser widget.'),
'#multiple' => TRUE,
'#default_value' => $this->configuration['allowed_properties'],
'#options' => $options,
];
} catch (\Exception $e) {
watchdog_exception('bynder', $e);
(new UnableToConnectException())
->displayMessage();
}
return $form;
}