public function BaseSettingsForm::validateAnPlacementId in Facebook Instant Articles 3.x
Same name and namespace in other branches
- 8.2 src/Form/BaseSettingsForm.php \Drupal\fb_instant_articles\Form\BaseSettingsForm::validateAnPlacementId()
Validate the Audience Network placement id.
Parameters
array $form: FAPI array.
\Drupal\Core\Form\FormStateInterface $form_state: Form state.
File
- src/
Form/ BaseSettingsForm.php, line 217
Class
- BaseSettingsForm
- Facebook Instant Articles base settings form.
Namespace
Drupal\fb_instant_articles\FormCode
public function validateAnPlacementId(array &$form, FormStateInterface $form_state) {
// Only validate if Audience Network is selected as ad type.
if ($form_state
->getValue('ads_type') != AdTypes::AD_TYPE_FBAN) {
return;
}
$ads_an_placement_id = $form_state
->getValue('ads_an_placement_id');
if (empty($ads_an_placement_id)) {
$form_state
->setErrorByName('ads_an_placement_id', $this
->t('You must specify a valid Placement ID when using the Audience Network ad type.'));
}
if (preg_match('/^[\\d_]+$/', $ads_an_placement_id) !== 1) {
$form_state
->setErrorByName('ads_an_placement_id', $this
->t('You must specify a valid Placement ID when using the Audience Network ad type. To find or set your placement id, you will need to go to your Audience Network account for Instant Articles. In the account, navigate to ‘Placements’ and create a ‘Placement of Banner’ type. You will only need one placement.'));
}
}