0

On a node field form (admin/structure/types/manage/article/fields), I have a dropdown with action links for all fields.

  • Edit
  • Storage Settings
  • Delete

I would like know if it's possible to unset the "Delete" link for a field please. I have try with hook_link_alter() but I don't know how find and remove the link for a specific field (by example field_image).

Thanks.

0

Assuming those operations check access correctly (not doing so would be a bug), you can use hook_ENTITY_TYPE_access, e.g. in your case hook_field_config_access, there you can deny delete access for a field with a given name.

0

to find the location of the field you want to unset, use the Devel Module:

Helper functions for Drupal developers and inquisitive admins. This module can print a summary of all database queries for each page request at the bottom of each page. The summary includes how many times each query was executed on a page (shouldn't run same query multiple times), and how long each query took (short is good - use cache for complex queries). Also a dprint_r($array) function is provided, which pretty prints arrays. Useful during development. Similarly, a ddebug_backtrace() is offerred. much more. See this helpful demo page.

then you could use hook_form_alter() to actually unset the value. to get the form information, something like:

hook_form_alter(&$form, &$form_state, $form_id)
{
  dpm($form); // from devel module

  if($form_id == FORM_ID_THAT_HOLDS_ELEMENT_TO_HIDE)
  {
    unset($form[field]...);
  }
}

dpm will show the structure of any array, including the form - you can drill down into the data to find the exact location of the item you want to unset

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.