You are here

public function TimestampExport::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 FieldTypeExportBase::buildConfigurationForm

File

src/Plugin/FieldTypeExport/TimestampExport.php, line 45

Class

TimestampExport
Defines a Timestamp field type export plugin.

Namespace

Drupal\entity_export_csv\Plugin\FieldTypeExport

Code

public function buildConfigurationForm(array $form, FormStateInterface $form_state, FieldDefinitionInterface $field_definition) {
  $configuration = $this
    ->getConfiguration();
  $build = parent::buildConfigurationForm($form, $form_state, $field_definition);
  $date_formats = [];
  $date_formats[''] = $this
    ->t('None');
  foreach ($this->entityTypeManager
    ->getStorage('date_format')
    ->loadMultiple() as $machine_name => $value) {
    $date_formats[$machine_name] = $this
      ->t('@name format: @date', [
      '@name' => $value
        ->label(),
      '@date' => $this->dateFormatter
        ->format(REQUEST_TIME, $machine_name),
    ]);
  }
  $date_formats['custom'] = $this
    ->t('Custom');
  $build['custom_date_format'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Custom date format'),
    '#description' => $this
      ->t('See <a href="http://php.net/manual/function.date.php" target="_blank">the documentation for PHP date formats</a>.'),
    '#default_value' => !empty($configuration['custom_date_format']) ? $configuration['custom_date_format'] : '',
  ];
  $build['custom_date_format']['#states']['visible'][] = [
    ':input[name="fields[' . $field_definition
      ->getName() . '][form][options][format]"]' => [
      'value' => 'custom',
    ],
  ];
  return $build;
}