function fb_instant_articles_form_node_type_form_submit 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_submit()
Submit function for the node type form with the FBIA toggle.
1 string reference to 'fb_instant_articles_form_node_type_form_submit'
File
- ./
fb_instant_articles.module, line 138 - Contains fb_instant_articles.module..
Code
function fb_instant_articles_form_node_type_form_submit(&$form, FormStateInterface $form_state) {
$entity_type = $form_state
->getValue('type');
if ($form_state
->getValue('fb_instant_articles_enabled') === 1) {
/** @var \Drupal\Core\Entity\Display\EntityViewDisplayInterface $display */
if ($display = \Drupal::entityTypeManager()
->getStorage('entity_view_display')
->load('node.' . $entity_type . '.fb_instant_articles')) {
$display
->setStatus(TRUE)
->save();
}
else {
// Create a new view mode if it's not already created.
$display = EntityViewDisplay::create([
'id' => 'node.' . $entity_type . '.fb_instant_articles',
'targetEntityType' => 'node',
'bundle' => $entity_type,
'mode' => 'fb_instant_articles',
'status' => TRUE,
]);
$display
->save();
}
}
else {
/** @var \Drupal\Core\Entity\Display\EntityDisplayInterface $display */
if ($display = \Drupal::entityTypeManager()
->getStorage('entity_view_display')
->load('node.' . $entity_type . '.fb_instant_articles')) {
$display
->setStatus(FALSE)
->save();
}
}
}