Skip to content

Instantly share code, notes, and snippets.

@steffenr
Last active August 3, 2016 18:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save steffenr/512c7cd6cc23f51dfc7bf8fcb069f4cb to your computer and use it in GitHub Desktop.
Save steffenr/512c7cd6cc23f51dfc7bf8fcb069f4cb to your computer and use it in GitHub Desktop.
Add pseudo field to node edit form (works fine in combination with field_group module)
<?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