public function SimpleFacebookPixelSettingsForm::buildForm in Simple Facebook Pixel 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/ SimpleFacebookPixelSettingsForm.php, line 77
Class
- SimpleFacebookPixelSettingsForm
- Class SimpleFacebookPixelSettingsForm.
Namespace
Drupal\simple_facebook_pixel\FormCode
public function buildForm(array $form, FormStateInterface $form_state) {
$config = $this
->config('simple_facebook_pixel.settings');
$form['pixel_enabled'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Enable Facebook Pixel'),
'#default_value' => $config
->get('pixel_enabled'),
];
$form['basic_settings'] = [
'#type' => 'fieldset',
'#title' => $this
->t('Basic settings'),
'#open' => FALSE,
'#states' => [
'visible' => [
':input[name="pixel_enabled"]' => [
'checked' => TRUE,
],
],
],
];
$form['basic_settings']['pixel_id'] = [
'#type' => 'textfield',
'#title' => $this
->t('Facebook Pixel ID'),
'#description' => $this
->t('Your Facebook Pixel ID. Separate multiple Pixels with a comma.'),
'#default_value' => $config
->get('pixel_id'),
'#required' => TRUE,
'#states' => [
'visible' => [
':input[name="pixel_enabled"]' => [
'checked' => TRUE,
],
],
],
];
$form['basic_settings']['exclude_admin_pages'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Exclude admin pages'),
'#default_value' => $config
->get('exclude_admin_pages'),
];
$form['basic_settings']['excluded_roles'] = [
'#type' => 'checkboxes',
'#title' => $this
->t('Exclude Facebook Pixel for the following roles.'),
'#options' => array_map('\\Drupal\\Component\\Utility\\Html::escape', user_role_names()),
'#default_value' => $config
->get('excluded_roles'),
'#states' => [
'visible' => [
':input[name="pixel_enabled"]' => [
'checked' => TRUE,
],
],
],
];
$form['events'] = [
'#type' => 'fieldset',
'#title' => $this
->t('Events'),
'#open' => FALSE,
'#states' => [
'visible' => [
':input[name="pixel_enabled"]' => [
'checked' => TRUE,
],
],
],
];
$form['events']['page_view_notice'] = [
'#type' => 'markup',
'#markup' => '<p>' . $this
->t('PageView event is by default enabled on all pages. Other events can be enabled/disabled bellow.') . '</p>',
'#states' => [
'visible' => [
':input[name="pixel_enabled"]' => [
'checked' => TRUE,
],
],
],
];
$form['events']['view_content_entities'] = [
'#type' => 'checkboxes',
'#title' => $this
->t('Add ViewContent event to the following pages'),
'#options' => array_map('\\Drupal\\Component\\Utility\\Html::escape', $this
->getViewContentEntities()),
'#default_value' => $config
->get('view_content_entities'),
'#states' => [
'visible' => [
':input[name="pixel_enabled"]' => [
'checked' => TRUE,
],
],
],
];
$form['events']['complete_registration_notice'] = [
'#type' => 'markup',
'#markup' => '<strong>' . $this
->t('CompleteRegistration') . '</strong>',
'#states' => [
'visible' => [
':input[name="pixel_enabled"]' => [
'checked' => TRUE,
],
],
],
];
$form['events']['complete_registration_enabled'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Enable'),
'#default_value' => $config
->get('complete_registration_enabled'),
'#states' => [
'visible' => [
':input[name="pixel_enabled"]' => [
'checked' => TRUE,
],
],
],
];
if ($this->moduleHandler
->moduleExists('commerce_checkout')) {
$form['events']['initiate_checkout_notice'] = [
'#type' => 'markup',
'#markup' => '<strong>' . $this
->t('Initiate Checkout') . '</strong>',
'#states' => [
'visible' => [
':input[name="pixel_enabled"]' => [
'checked' => TRUE,
],
],
],
];
$form['events']['initiate_checkout_enabled'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Enable'),
'#default_value' => $config
->get('initiate_checkout_enabled'),
'#states' => [
'visible' => [
':input[name="pixel_enabled"]' => [
'checked' => TRUE,
],
],
],
];
$form['events']['purchase_notice'] = [
'#type' => 'markup',
'#markup' => '<strong>' . $this
->t('Purchase') . '</strong>',
'#states' => [
'visible' => [
':input[name="pixel_enabled"]' => [
'checked' => TRUE,
],
],
],
];
$form['events']['purchase_enabled'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Enable'),
'#default_value' => $config
->get('purchase_enabled'),
'#states' => [
'visible' => [
':input[name="pixel_enabled"]' => [
'checked' => TRUE,
],
],
],
];
$form['events']['add_to_cart_notice'] = [
'#type' => 'markup',
'#markup' => '<strong>' . $this
->t('AddToCart') . '</strong>',
'#states' => [
'visible' => [
':input[name="pixel_enabled"]' => [
'checked' => TRUE,
],
],
],
];
$form['events']['add_to_cart_enabled'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Enable'),
'#default_value' => $config
->get('add_to_cart_enabled'),
'#states' => [
'visible' => [
':input[name="pixel_enabled"]' => [
'checked' => TRUE,
],
],
],
];
}
if ($this->moduleHandler
->moduleExists('commerce_wishlist') || $this->moduleHandler
->moduleExists('flag')) {
$form['events']['add_to_wishlist_notice'] = [
'#type' => 'markup',
'#markup' => '<strong>' . $this
->t('AddToWishlist') . '</strong>',
'#states' => [
'visible' => [
':input[name="pixel_enabled"]' => [
'checked' => TRUE,
],
],
],
];
}
if ($this->moduleHandler
->moduleExists('commerce_wishlist')) {
$form['events']['add_to_wishlist_enabled'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Enable (using Commerce Wishlist module)'),
'#default_value' => $config
->get('add_to_wishlist_enabled'),
'#states' => [
'visible' => [
':input[name="pixel_enabled"]' => [
'checked' => TRUE,
],
],
],
];
}
if ($this->moduleHandler
->moduleExists('flag')) {
$form['events']['add_to_wishlist_flag_enabled'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Enable (using Flag module)'),
'#default_value' => $config
->get('add_to_wishlist_flag_enabled'),
'#states' => [
'visible' => [
':input[name="pixel_enabled"]' => [
'checked' => TRUE,
],
],
],
];
$form['events']['add_to_wishlist_flag_list'] = [
'#type' => 'checkboxes',
'#options' => $this
->getFlags(),
'#title' => $this
->t('Available flags'),
'#default_value' => $config
->get('add_to_wishlist_flag_list'),
'#states' => [
'visible' => [
':input[name="pixel_enabled"]' => [
'checked' => TRUE,
],
':input[name="add_to_wishlist_flag_enabled"]' => [
'checked' => TRUE,
],
],
],
'#prefix' => '<div class="available-flags">',
'#suffix' => '</div>',
];
}
$form['#attached']['library'][] = 'simple_facebook_pixel/simple_facebook_pixel.admin';
return parent::buildForm($form, $form_state);
}