2

How can you set #access to false for the vertical tab "Translation" (entity translation) on the node edit form?

When using entity translation and a user has the permission to edit a node and edit translations, a new vertical tab is injected in the node edit form:

Translation
Translation is published. Do notflag translation as outdated
[x] This translation is published
[ ] Flag translation as outdated

Since I have editors that need to edit translations but shall not have access to this v-tab (it is being confused with the Publishing options for the node, leading to people altering the translation status where the node in its entirety should be unpublished/published instead).

Using hook_form_alter() in a custom module, I do not find any trace of the above form element in the $form array. According to a grep search, it is defined in the file /modules/entity_translation/includes/translation.handler.inc:1051. I assume it is being cached somehow, as that part of the code is not being executed when the form is built (breakpoints do not trigger).

Worst case, I could use Javascript to hide the form element, but I would rather not have to rely on such a hack. If possible, I would like to set #access to false for the editor role (or similar).

1 Answer 1

2

The reason you cannot use hook_form_alter() to modify the tabs is because the hook you implement in your custom module is being fired before entity translation injects the tab.

If you use hook_module_implements_after() you can change the order of the execution of the hooks.

function CUSTOMMODULE_module_implements_alter(&$modules, $hook)
{
    if ($hook == "form_alter")
    {
print_r($modules);
        // save off hook
        $temp = $modules["testing"];

        // remove it
        unset($modules["testing"]);

        // add it to the end
        $modules["testing"] = $temp;
print_r($modules);
    }
}

The first print_r outputs:

Array
(
    ...
    [CUSTOMMODULE] => 
    [entity_translation] => 
)

The second print_r outputs:

Array
(
    ...
    [entity_translation] => 
    [CUSTOMMODULE] => 
)

Now that the custom module fires after entity translation, use hook_form_alter() to hide the tab:

function CUSTOMMODULE_form_alter(&$form, &$form_state, $form_id)
{
    // make sure you set the form_id in this conditional properly.
    // I am using the edit form of a "page" node type.
    if ($form_id == "page_node_form")
    {
        $form["translation"]["#access"] = FALSE;
    }
}
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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