function fb_instant_articles_form_node_type_form_alter in Facebook Instant Articles 3.x
Same name and namespace in other branches
- 8.2 fb_instant_articles.module \fb_instant_articles_form_node_type_form_alter()
Implements hook_form_FORM_ID_alter() for \Drupal\node\NodeTypeForm.
See also
fb_instant_articles_form_node_type_form_builder()
File
- ./
fb_instant_articles.module, line 91 - Contains fb_instant_articles.module..
Code
function fb_instant_articles_form_node_type_form_alter(&$form, FormStateInterface $form_state) {
/** @var \Drupal\node\NodeTypeInterface $node_type */
$node_type = $form_state
->getFormObject()
->getEntity();
// Add a vertical tab to the node type form.
$form['fb_instant_articles'] = [
'#type' => 'details',
'#title' => t('Facebook Instant Articles'),
'#group' => 'additional_settings',
'#access' => \Drupal::currentUser()
->hasPermission('administer fb_instant_articles'),
];
// Facebook Instant Articles enabled checkbox.
$form['fb_instant_articles']['fb_instant_articles_enabled'] = [
'#type' => 'checkbox',
'#title' => t('Enable Facebook Instant Articles'),
'#description' => t('Enable content of this type with support for Facebook Instant Articles.'),
'#weight' => 0,
'#default_value' => $node_type
->getThirdPartySetting('fb_instant_articles', 'fb_instant_articles_enabled'),
];
// Use an #entity_builder callback to edit a third party setting on the node
// type entity before it gets saved to the database.
$form['#entity_builders'][] = 'fb_instant_articles_form_node_type_form_builder';
// Use a #submit callback to save a entity view display entity. This has to be
// on #submit so that the node type entity has been saved since the entity
// view display entity is dependent on the node type entity.
$form['actions']['submit']['#submit'][] = 'fb_instant_articles_form_node_type_form_submit';
}