1

I have a custom entity in Drupal7 created using the Entity API. I am attempting to make it work with the meta tag module. I have added

'metatags' => TRUE

to hook_entity_info, and metatags display as a field under "manage fields" for the entity. The trouble is that the vertical tabs that usually display on every node do not show up on the entity. Thus, I have no way of changing any of the information in the meta tag field on the custom entity. How do you make the vertical tabs appear when using entity api? (The following image shows what I am missing on every entity I create with Entity API)

2

This seems to be the reverse of the question remove vertical tabs, and should have a very similar answer. In the documentation for the vertical tabs module, the first code snippet is how to enable vertical tabs on any form. The second snippet looks more appropriate, as it is how to enable tabs from your custom module that creates your custom entity.

<?php
$vtabs = variable_get('vertical_tabs_forms', array());

// Enable vertical tabs on a form.
$vtabs['my_form_id'] = TRUE;

// Disable vertical tabs on a form.
$vtabs['page_node_form'] = FALSE;

// Enable vertical tabs but be selective of which fieldsets are included. 
$vtabs['page_node_form'] = array('menu' => FALSE);

variable_set('vertical_tabs_forms', $vtabs);
?>

Edit:

The site variables here is a huge array that is always accessible to drupal. Some of these settings can be stored in your site's settings.php file, as this variables array is present even there. However, because of the nature of the change that you desire, I think the best choice for you is to have a hook_install in the module that defines your custom entity.

Assuming module name "your_entity", add a file "your_entity.install" to the module.

function your_entity_install() {
  // Enable vertical tabs on entity form.
  // this is supposed to be true as long as this module is enabled
  $vtabs = variable_get('vertical_tabs_forms', array());
  $vtabs['your_entity_form'] = TRUE;
  variable_set('vertical_tabs_forms', $vtabs);
}

Then disable and re-enable your module. These variables can be set in the form_alter, but that would only be recommended if you needed the value to change based on other information that is not present at an earlier time.

  • Thank you for helping point me in the right direction. This answer got me partially there. I went ahead and added $form['#pre_render'][] = 'vertical_tabs_form_pre_render'; to my form. This rendered the output of the redirect module in a fieldset on the form, but it did not show the vertical tabs or the meta-tag fields. I attempted the above verbatim in hook_form_alter without any results... – ancapaaron Aug 17 '15 at 19:35
  • The above is copied straight from the documentation. I do not know the id of the form you are working on, it usually contains the machine name of the content type. The pre_render is a great addition. You should only need the 3 lines to get the tabs turned on: variable_get (so you do not overwrite the settings from the rest of the site), $vtabs['your_custom_entity_form_id'] = TRUE; variable_set (tell the site of your change) – DeveloperWeeks Aug 17 '15 at 19:45
  • Also, since this is a site variable change, it might work in the form_alter but it would be better to do it in the hook_install() for your custom entity module. Unless you have reason for the form to have vertical tabs sometimes and not other times. – DeveloperWeeks Aug 17 '15 at 19:56
  • I went ahead and did this in install, and checked that the vertical tabs variable was set using the devel module. [my_form_id] => 1(not literally my_form_id, but the correct id is in there and set). Still nothing... I went ahead and looked to see if the vertical-tabs.js is being included on the form, and it is not. I am fairly certain that is a problem, and am not sure if the above will automagically include the js? – ancapaaron Aug 17 '15 at 20:26
  • drupal_add_library('system', 'drupal.vertical-tabs'); @ancapaaron – Clive Aug 18 '15 at 8:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.