You are here

public function ResponsiveFaviconsAdmin::buildForm in Responsive Favicons 8

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 ConfigFormBase::buildForm

File

src/Form/ResponsiveFaviconsAdmin.php, line 60

Class

ResponsiveFaviconsAdmin
Class ResponsiveFaviconsAdmin.

Namespace

Drupal\responsive_favicons\Form

Code

public function buildForm(array $form, FormStateInterface $form_state) {
  $config = $this
    ->config('responsive_favicons.settings');
  $form['path_type'] = [
    '#type' => 'radios',
    '#title' => $this
      ->t('Favicons location'),
    '#description' => $this
      ->t('Upload favicons using zip file from realfavicongenerator.net or provide path with location of the files.'),
    '#options' => [
      'upload' => $this
        ->t('Upload zip file'),
      'path' => $this
        ->t('Use internal path'),
    ],
    '#default_value' => $config
      ->get('path_type'),
  ];
  $form['upload_path'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Path to responsive favicon files'),
    '#description' => $this
      ->t('A local file system path where favicon files will be stored. This directory must exist and be writable by Drupal. An attempt will be made to create this directory if it does not already exist.'),
    '#field_prefix' => file_create_url('public://'),
    '#default_value' => $config
      ->get('path'),
    '#states' => [
      'visible' => [
        ':input[name="path_type"]' => [
          'value' => 'upload',
        ],
      ],
    ],
  ];
  $form['local_path'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Path to responsive favicon files'),
    '#description' => $this
      ->t('A local file system path where favicon files are stored (e.g. <code>/themes/custom/your-theme/favicons</code>). This directory must exist, relative to your Drupal root and contain all required files.'),
    '#default_value' => $config
      ->get('path'),
    '#field_prefix' => DRUPAL_ROOT,
    '#states' => [
      'visible' => [
        ':input[name="path_type"]' => [
          'value' => 'path',
        ],
      ],
    ],
  ];
  $form['tags'] = [
    '#type' => 'textarea',
    '#title' => $this
      ->t('Favicon tags'),
    '#description' => $this
      ->t('Paste the code provided by <a href="http://realfavicongenerator.net/" target="_blank">http://realfavicongenerator.net/</a>. Make sure each link is on a separate line. It is fine to paste links with paths like <code>/apple-touch-icon-57x57.png</code> as these will be converted to the correct paths automatically.'),
    '#default_value' => implode(PHP_EOL, $config
      ->get('tags')),
    '#rows' => 16,
  ];
  $form['upload'] = [
    '#type' => 'file',
    '#title' => $this
      ->t('Upload a zip file from realfavicongenerator.net to install'),
    '#description' => $this
      ->t('For example: %filename from your local computer. This only needs to be done once.', [
      '%filename' => 'favicons.zip',
    ]),
    '#states' => [
      'visible' => [
        ':input[name="path_type"]' => [
          'value' => 'upload',
        ],
      ],
    ],
  ];
  $form['remove_default'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Remove default favicon from Drupal'),
    '#description' => $this
      ->t('It is recommended to remove default favicon as it can cause issues'),
    '#default_value' => $config
      ->get('remove_default'),
  ];
  return parent::buildForm($form, $form_state);
}