You are here

public function GoogleImageSitemapCreateForm::buildForm in Google Image Sitemap 2.0.x

Same name and namespace in other branches
  1. 8 src/Form/GoogleImageSitemapCreateForm.php \Drupal\google_image_sitemap\Form\GoogleImageSitemapCreateForm::buildForm()
  2. 1.0.x src/Form/GoogleImageSitemapCreateForm.php \Drupal\google_image_sitemap\Form\GoogleImageSitemapCreateForm::buildForm()

Form constructor.

Parameters

array $form: An associative array containing the structure of the form.

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.

Return value

array The form structure.

Overrides FormInterface::buildForm

File

src/Form/GoogleImageSitemapCreateForm.php, line 25

Class

GoogleImageSitemapCreateForm
Provides a form to create new sitemap.

Namespace

Drupal\google_image_sitemap\Form

Code

public function buildForm(array $form, FormStateInterface $form_state, $edit = NULL) {
  $form = [];

  // Get all node types, and add an All option.
  $node_types = array_merge([
    'all' => $this
      ->t('--All--'),
  ], node_type_get_names());
  $form['node_type'] = [
    '#type' => 'select',
    '#title' => $this
      ->t('Select Content Type'),
    '#description' => $this
      ->t('Select the content type for which you want to generate image sitemap.'),
    '#options' => $node_types,
    '#default_value' => !empty($edit->node_type) ? $edit->node_type : '',
    '#required' => TRUE,
  ];
  $form['license'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('License url'),
    '#default_value' => !empty($edit->license) ? $edit->license : '',
    '#description' => $this
      ->t('An absolute url to the license agreement of the image.'),
  ];
  $form['buttons']['save'] = [
    '#type' => 'submit',
    '#value' => $this
      ->t('Save'),
  ];
  $form['cancel'] = [
    '#type' => 'link',
    '#title' => $this
      ->t('Cancel'),
    '#url' => Url::fromRoute('google_image_sitemap.list'),
  ];
  if ($edit) {
    $del = 'admin/config/search/google_image_sitemap/delete/' . $edit->sid;
    $form['delete'] = [
      '#type' => 'link',
      '#title' => $this
        ->t('Delete'),
      '#attributes' => [
        'class' => 'button button--danger',
      ],
      '#url' => Url::fromUri('internal:/' . $del),
    ];
  }
  return $form;
}