public function Pinterest::buildConfigurationForm in Media entity Pinterest 8
Form constructor.
Plugin forms are embedded in other forms. In order to know where the plugin form is located in the parent form, #parents and #array_parents must be known, but these are not available during the initial build phase. In order to have these properties available when building the plugin form's elements, let this method return a form element that has a #process callback and build the rest of the form in the callback. By the time the callback is executed, the element's #parents and #array_parents properties will have been set by the form API. For more documentation on #parents and #array_parents, see \Drupal\Core\Render\Element\FormElement.
Parameters
array $form: An associative array containing the initial structure of the plugin form.
\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form. Calling code should pass on a subform state created through \Drupal\Core\Form\SubformState::createForSubform().
Return value
array The form structure.
Overrides MediaTypeBase::buildConfigurationForm
File
- src/
Plugin/ MediaEntity/ Type/ Pinterest.php, line 159
Class
- Provides media type plugin for Pinterest.
Namespace
Drupal\media_entity_pinterest\Plugin\MediaEntity\TypeCode
public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
// TODO: Implement buildConfigurationForm() method.
/** @var \Drupal\media_entity\MediaBundleInterface $bundle */
$bundle = $form_state
->getFormObject()
->getEntity();
$options = [];
$allowed_field_types = [
'string',
'string_long',
'link',
];
foreach ($this->entityFieldManager
->getFieldDefinitions('media', $bundle
->id()) as $field_name => $field) {
if (in_array($field
->getType(), $allowed_field_types) && !$field
->getFieldStorageDefinition()
->isBaseField()) {
$options[$field_name] = $field
->getLabel();
}
}
$form['source_field'] = [
'#type' => 'select',
'#title' => $this
->t('Field with source information'),
'#description' => $this
->t('Field on media entity that stores Pinterest embed code or URL. You can create a bundle without selecting a value for this dropdown initially. This dropdown can be populated after adding fields to the bundle.'),
'#default_value' => empty($this->configuration['source_field']) ? NULL : $this->configuration['source_field'],
'#options' => $options,
];
$form['use_pinterest_api'] = [
'#type' => 'select',
'#title' => $this
->t('Whether to use Pinterest api to fetch pin or not.'),
'#description' => $this
->t("In order to use Pinterest's api you have to create a developer account and an application. For more information consult the readme file."),
'#default_value' => empty($this->configuration['use_pinterest_api']) ? 0 : $this->configuration['use_pinterest_api'],
'#options' => [
0 => $this
->t('No'),
],
];
// TODO: Implement buildConfigurationForm() method for API fields.
return $form;
}