Last active
August 3, 2016 18:19
Add pseudo field to node edit form (works fine in combination with field_group module)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Implements hook_form_alter(). | |
*/ | |
function mymodule_form_alter(&$form, \Drupal\Core\Form\FormStateInterface $form_state, $form_id) { | |
if ($form_id == 'node_article_edit_form') { | |
$form['my_view'] = [ | |
'#markup' => 'Some arbitrary markup.', | |
]; | |
// Access entity object. | |
$entity = $form_state->getFormObject()->getEntity()->id(); | |
} | |
} | |
/** | |
* Implements hook_entity_extra_field_info(). | |
*/ | |
function mymodule_entity_extra_field_info() { | |
$extra = array(); | |
foreach (NodeType::loadMultiple() as $bundle) { | |
$extra['node'][$bundle->id()]['form']['my_view'] = array( | |
'label' => t('myView'), | |
'description' => t('Display my view in here'), | |
'weight' => 100, | |
'visible' => TRUE, | |
); | |
} | |
return $extra; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment