public function FieldTypeExportBase::buildConfigurationForm in Entity Export CSV 8
Build the configuration form.
Parameters
array $form: The configuration form.
\Drupal\Core\Form\FormStateInterface $form_state: The form_state object.
\Drupal\Core\Field\FieldDefinitionInterface $field_definition: The field definition.
Return value
mixed The configuration form.
Overrides FieldTypeExportInterface::buildConfigurationForm
4 calls to FieldTypeExportBase::buildConfigurationForm()
- DateRangeExport::buildConfigurationForm in src/
Plugin/ FieldTypeExport/ DateRangeExport.php - Build the configuration form.
- DateTimeExport::buildConfigurationForm in src/
Plugin/ FieldTypeExport/ DateTimeExport.php - Build the configuration form.
- GeolocationExport::buildConfigurationForm in src/
Plugin/ FieldTypeExport/ GeolocationExport.php - Build the configuration form.
- TimestampExport::buildConfigurationForm in src/
Plugin/ FieldTypeExport/ TimestampExport.php - Build the configuration form.
4 methods override FieldTypeExportBase::buildConfigurationForm()
- DateRangeExport::buildConfigurationForm in src/
Plugin/ FieldTypeExport/ DateRangeExport.php - Build the configuration form.
- DateTimeExport::buildConfigurationForm in src/
Plugin/ FieldTypeExport/ DateTimeExport.php - Build the configuration form.
- GeolocationExport::buildConfigurationForm in src/
Plugin/ FieldTypeExport/ GeolocationExport.php - Build the configuration form.
- TimestampExport::buildConfigurationForm in src/
Plugin/ FieldTypeExport/ TimestampExport.php - Build the configuration form.
File
- src/
Plugin/ FieldTypeExportBase.php, line 147
Class
- FieldTypeExportBase
- Base class for Field type export plugins.
Namespace
Drupal\entity_export_csv\PluginCode
public function buildConfigurationForm(array $form, FormStateInterface $form_state, FieldDefinitionInterface $field_definition) {
$build = [];
$configuration = $this
->getConfiguration();
$field_name = $field_definition
->getName();
$build['header'] = [
'#type' => 'radios',
'#title' => $this
->t('Header'),
'#options' => $this
->getHeaderOptions(),
'#default_value' => $configuration['header'],
'#required' => TRUE,
'#attributes' => [
'class' => [
'inline-radios',
],
],
];
$properties = $this
->getPropertyExportOptions($field_definition);
$main_property = $this
->getMainPropertyName($field_definition);
$allow_export_multiple_properties = $this
->allowExportMultipleProperties($field_definition);
if (isset($properties[$main_property])) {
$default_property = $main_property;
}
else {
$properties_keys = array_keys($properties);
$default_property = reset($properties_keys);
}
$build['property'] = [
'#type' => 'checkboxes',
'#title' => $this
->t('Property'),
'#options' => $properties,
'#default_value' => !empty($configuration['property']) ? $configuration['property'] : [
$default_property,
],
'#required' => (bool) (!empty($properties)),
'#attributes' => [
'class' => [
'inline-radios',
],
],
];
$build['property_separator'] = [
'#type' => 'select',
'#title' => $this
->t('Property separator'),
'#description' => $this
->t('The separator used if multiple properties are selected to be exported in one column.'),
'#options' => $this
->getPropertyColumnSeparatorOptions($field_definition),
'#default_value' => $configuration['property_separator'],
'#access' => $allow_export_multiple_properties,
'#states' => [
'visible' => [
':input[name="fields[' . $field_name . '][form][options][property_separate_column]"]' => [
'checked' => FALSE,
],
],
],
];
$build['property_separate_column'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Export each property selected into a separate column'),
'#default_value' => $configuration['property_separate_column'],
'#access' => $allow_export_multiple_properties,
];
$build['format'] = [
'#type' => 'select',
'#title' => $this
->t('Format'),
'#options' => $this
->getFormatExportOptions($field_definition),
'#default_value' => !empty($configuration['format']) ? $configuration['format'] : '',
];
$max_columns = $this
->getMaxColumns();
if ($this
->fieldDefinitionIsMultiple($field_definition) && $max_columns > 1) {
$columns = [
'' => $this
->t('Same column'),
];
for ($i = 2; $i < $max_columns + 1; $i++) {
$columns[$i] = $this
->t('@number columns', [
'@number' => $i,
]);
}
$build['explode'] = [
'#type' => 'select',
'#title' => $this
->t('Columns to explode multiple values'),
'#description' => $this
->t('Select the number of columns you want to export this multiple field. For this field, this setting will generate the number of columns set. Select <em>Same column</em> to export all values into a unique column.'),
'#options' => $columns,
'#default_value' => isset($configuration['explode']) ? $configuration['explode'] : '',
];
}
if ($this
->fieldDefinitionIsMultiple($field_definition)) {
$build['separator'] = [
'#type' => 'select',
'#title' => $this
->t('Separator'),
'#options' => $this
->getSeparatorsOptions(),
'#default_value' => $configuration['separator'],
"#required" => TRUE,
'#states' => [
'visible' => [
':input[name="fields[' . $field_name . '][form][options][explode]"]' => [
'value' => '',
],
],
],
];
}
return $build;
}