public function ViewportSettingsForm::buildForm in Viewport 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/ ViewportSettingsForm.php, line 31
Class
- ViewportSettingsForm
- Class to configure viewport settings for this site.
Namespace
Drupal\viewport\FormCode
public function buildForm(array $form, FormStateInterface $form_state) {
$viewportSettings = $this
->configFactory()
->get('viewport.settings');
$form['viewport'] = array(
'#type' => 'fieldset',
);
$form['viewport']['width'] = array(
'#type' => 'textfield',
'#title' => $this
->t('Width'),
'#default_value' => $viewportSettings
->get('width'),
'#description' => $this
->t('You probably want this to be %device-width, but a fixed number of pixels (only the number) is accepted too.', array(
'%device-width' => 'device-width',
)),
);
$form['viewport']['height'] = array(
'#type' => 'textfield',
'#title' => $this
->t('Height'),
'#default_value' => $viewportSettings
->get('height'),
'#description' => $this
->t('%device-height, or a fixed number of pixels (only the number).', array(
'%device-height' => 'device-height',
)),
);
$form['viewport']['initial_scale'] = array(
'#type' => 'textfield',
'#title' => $this
->t('Initial Scale'),
'#default_value' => $viewportSettings
->get('initial_scale'),
'#description' => $this
->t('Any value in the range (0, 10.0]. Usually this is set to 1.0'),
);
$form['viewport']['minimum_scale'] = array(
'#type' => 'textfield',
'#title' => $this
->t('Minimum Scale'),
'#default_value' => $viewportSettings
->get('minimum_scale'),
'#description' => $this
->t('Any value in the range (0, 10.0]. Usually this is set to the same value as the %initial-scale property', array(
'%initial-scale' => 'initial-scale',
)),
);
$form['viewport']['maximum_scale'] = array(
'#type' => 'textfield',
'#title' => $this
->t('Maximum Scale'),
'#default_value' => $viewportSettings
->get('maximum_scale'),
'#description' => $this
->t('Any value in the range (0, 10.0]. Usually this is set to 1.0'),
);
$form['viewport']['user_scalable'] = array(
'#type' => 'checkbox',
'#title' => $this
->t('User Scalable'),
'#default_value' => $viewportSettings
->get('user_scalable'),
);
$form['viewport']['selected_pages'] = array(
'#type' => 'textarea',
'#title' => $this
->t('Selected pages'),
'#default_value' => $viewportSettings
->get('selected_pages'),
'#description' => $this
->t("The viewport settings will be applied to the following paths. <br/>\n Specify pages by using their paths. Enter one path per line. The '*' character is a wildcard.\n Example paths are %node for the first node of the site and %node-wildcard for every node.\n %front is the front page.<br>\n Note in Drupal 8 paths are preceded by a forward slash %slash.", array(
'%node' => '/node',
'%node-wildcard' => '/node*',
'%front' => '<front>',
'%slash' => '"/"',
)),
);
return parent::buildForm($form, $form_state);
}