For 2 days I'm trying to list all the fields of the Entity Reference field. as descried in the attached photo but I can not ...
please inform how do I change the fields that will be listed in the form.
I want to hide the status field and add other 2 fields to the list...
I chose render entity in manage display field .... I check the teaser.... I google the issue...
no solution

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

ashrafabed’s picture

Use hook_inline_entity_form_table_fields_alter() in a custom module to add/remove fields

For example, this is how I removed the title field and added the body field to the content type 'my_content_type':


/**
 * Implements hook_inline_entity_form_table_fields_alter().
 */
function MY_CUSTOM_MODULE_inline_entity_form_table_fields_alter(&$fields, $context) {
    // Make sure there's a stock field on each of the allowed product types.
    $is_my_content_type = FALSE;
    foreach ($context['allowed_bundles'] as $bundle) {
      if ($bundle=='my_content_type') {
        $is_my_content_type = TRUE;
      }
    }
    if ($is_my_content_type) {
      unset($fields['title']);                       // This line removes the title field. you're looking to do this, just with the status instead of title field

      $fields['body'] = array(                   // This part adds the body field with a label 'description'
        'type' => 'field',
        'label' => t('Description'),
        'weight' => 101,
      );
    }
}
msh2050’s picture

Dear ashabed thanks a lot for your replay it really great...
honestly I'm coming from Vb.net to Drupal (witch depend on PHP )

I start using drupal from 2 weeks only.

the above code is very clear and easy to modify as per my needs...

I learn about hook and module customization as per the below video"
hook form alter

then I just apply your code with changing the field name "please find the attached file of the custom module"

with best regard

bojanz’s picture

Status: Active » Fixed
msh2050’s picture

Sorry bojanz
I forget to write that this did not solve the problem and make no change in the form
to dive more details:
I have a content of tender with a reference field to tender_details content "witch contain item and required quantity ....etc...

So I make a custom module "as in attachment" enabled then add ashabed code with changing the My content type field with tender_detail and is_my_content_type with is_tender_details...

but I did not get any changes in the form neither the title removed nor the new field appear..

Please help

msh2050’s picture

Status: Fixed » Needs review

I change the status, hope I can find the solution but I feel I'm closer to fix...

I try to use the modules and codes in the Investigate a UI for configuring table columns (which fields and in what order) post 21
the I edit it with post 25 to use for all content type..
it show very useful tab to edit the display field and controls but unfortunately their may be some error since I cannot edit or add any content that use inline entity form...

I write more details there https://drupal.org/node/1521274#comment-7880303

ashrafabed’s picture

msh2050, I opened your zip file and noticed one big issue:

/**
* Implements hook_inline_entity_form_table_fields_alter().
*/
function MY_CUSTOM_MODULE_inline_entity_form_table_fields_alter(&$fields, $context) {

You have to change 'MY_CUSTOM_MODULE to the machine name of your module.

So, your Costum_Inline_intity_form.module file should be something like:

/**
* Implements hook_inline_entity_form_table_fields_alter().
*/
function costum_inline_intity_form_inline_entity_form_table_fields_alter(&$fields, $context) {
    // Make sure there's a stock field on each of the allowed product types.
    $is_tender_detail = FALSE;
    foreach ($context['allowed_bundles'] as $bundle) {
      if ($bundle=='tender_detail') {
        $is_tender_detail = TRUE;
      }
    }
    if ($is_tender_detail) {
      unset($fields['title']);                       // This line removes the title field. you're looking to do this, just with the status instead of title field

      $fields['field_required_quantity'] = array(                   // This part adds the body field with a label 'description'
        'type' => 'field_required_quantity',
        'label' => t('Required Qty'),
        'weight' => 101,
      );
    }
}

Try it out and let me know what you get.

msh2050’s picture

Status: Needs review » Fixed
FileSize
58.77 KB

Dear ashabed

Many Many thanks It work for me and I really enjoying changing the fields...
I made some extra changes just for testing ...
I hide both title and status...(As in attachment)

but the format of the decimal field is not same the format that I configured in field stetting and in display management(how I can make the scale = 0 rather that currently(witch is 2)

below is the final code in case some one need it:

<?php
/**
* Implements hook_inline_entity_form_table_fields_alter().
*/
function costum_inline_intity_form_inline_entity_form_table_fields_alter(&$fields, $context) {
    // Make sure there's a stock field on each of the allowed product types.
    $is_tender_detail = FALSE;
    foreach ($context['allowed_bundles'] as $bundle) {
      if ($bundle=='tender_detail') {
        $is_tender_detail = TRUE;
      }
    }
    if ($is_tender_detail) {
		
		
// This line removes the title field. you're looking to do this, just with the status instead of title field
      unset($fields['title']); 
	  unset($fields['status']);                       


// This part adds stock fields with a label '
      $fields['field_required_quantity'] = array(                   
        'type' => 'field',
        'label' => t('Required Qty'),
		'scale' => 2,
	    'weight' => 101,
      );
	  
	  $fields['field_items_ref'] = array(                   
        'type' => 'field',
        'label' => t('Item Name'),
        'weight' => 100,
      );
	  
	  
    }
}
?>
ashrafabed’s picture

Assigned: msh2050 » ashrafabed

Maybe this should be a new issue... but you said "(how I can make the scale = 0 rather that currently(witch is 2)"..and your code says

// This part adds stock fields with a label '
      $fields['field_required_quantity'] = array(                   
        'type' => 'field',
        'label' => t('Required Qty'),
        'scale' => 2,
        'weight' => 101,
      );

Before looking into it, could it simply be changing 'scale' => 2, to 'scale' => 0,?

msh2050’s picture

yes it work greatly... thanks a lot for your cooperation ....

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

baddysonja’s picture

Assigned: ashrafabed » Unassigned
Issue summary: View changes

This is great and it works goot. I only have a problem with the formatting of f.x. an integer field. I have configured the field to be shown: 1.300,45 but I can't get the field to show this format. It only shows: 1 300.45
Any ideas?

Makku01’s picture

did you accomplish this baddysonja?

argiepiano’s picture

Thank you so much for this. I have a avery basic understanding of PHP, but this was easy to implement

drewpal3’s picture

This works well. I was able to changed the scale.

// This part adds stock fields with a label '
      $fields['field_required_quantity'] = array(
        'type' => 'field',
        'label' => t('Required Qty'),
        'settings' => array('precision' => 8, 'scale' => 0, 'decimal_separator' => '.'),
        'weight' => 101,
      )
operawong’s picture

The code doesn't work for me,
In my project , there are two node types , one is 'people' ,one is 'case' ,
I wish when user add node 'case' can use Inline Entity Form to add node 'people',
I set all 'people' fields to Required, but it seem doesn't work,
'title' and 'status' field still was shown.

here is my Costum_Inline_intity_form.module

/**
* Implements hook_inline_entity_form_table_fields_alter().
*/
function costum_inline_intity_form_inline_entity_form_table_fields_alter(&$fields, $context) {
    // Make sure there's a stock field on each of the allowed product types.
    $is_tender_detail = FALSE;
    foreach ($context['allowed_bundles'] as $bundle) {
      if ($bundle=='tender_detail') {
        $is_tender_detail = TRUE;
      }
    }
    if ($is_tender_detail) {
        
        
// This line removes the title field. you're looking to do this, just with the status instead of title field
      unset($fields['title']); 
      unset($fields['status']);                       
// This part adds stock fields with a label '
      $fields['field_required_quantity'] = array(                   
        'type' => 'field_required_quantity',
        'label' => t('Required Qty'),
        'scale' => 0,
        'weight' => 101,
      );      
    }
}
argiepiano’s picture

@operawong: there could be many reasons why it is not working. As a first step, I would verify that the hook is actually being invoked. Add a line like
set_drupal_message('I made it here!', 'status'); right before $is_tender_detail = FALSE;, save the module, refresh your cache and visit the page that has the inline entity form. If you don't see a status message "I made it here!" then you know the hook is not being invoked. That's a good start.

If you find out the hook is being invoked, then I would make sure to check that the name of the bundle ('tender_detail') actually matches the name of YOUR bundle, and that the names of the fields you are changing with unset(); match the names of the fields in your bundle.

Alternatively you can install the module Devel (https://www.drupal.org/project/devel) and insert the lines dpm($context); and dpm$(fields) instead of the set_drupal_message() above to inspect the contents of those two variables, which should allow you to match the names of the bundle and fields.

Always clear cache.

I hope this helps.

argiepiano’s picture

@operawong, one more thing. Be sure the name of your module ("Costum_ ...) uses only lowercase letters. It must match the first part of the name of your hook.

operawong’s picture

Thanks argiepiano , but I didn't see the message 'I made it here!'
here is part of my code

/**
* Implements hook_inline_entity_form_table_fields_alter().
*/
function costum_inline_intity_form_inline_entity_form_table_fields_alter(&$fields, $context) {
    // Make sure there's a stock field on each of the allowed product types.
  set_drupal_message('I made it here!', 'status'); 
    $is_tender_detail = FALSE;
    foreach ($context['allowed_bundles'] as $bundle) {
      if ($bundle=='tender_detail') {
        $is_tender_detail = TRUE;
      }
    }
    if ($is_tender_detail) {
// This line removes the title field. you're looking to do this, just with the status instead of title field

      unset($fields['status']);                 
// This part adds stock fields with a label '
      $fields['field_required_quantity'] = array(                   
        'type' => 'field',
        'label' => t('field_people_name'),
        'scale' => 0,
        'weight' => 101,
      );
    }
}
operawong’s picture

argiepiano’s picture

@operawong: since the message was never displayed, that's an indication that the hook implementation was never invoked. This may be most likely to a mistake in how you created the module. The file you attached must be in a folder inside the sites/all/modules folder. The folder must be called EXACTLY like the first part of the hook (costum_inline_intity_form). The module must be called costum_inline_intity_form.module. And the folder must contain an info file called costum_inline_intity_form.info with specific code inside. If this is the first module you create I'd suggest careful attention to this tutorial: https://www.drupal.org/developing/modules/7 (by the way, if you did all this, have you enabled the module you created?)

If you did follow those steps carefully, you should see the "I made it here!" message every time drupal renders an Inline Entity Form.

operawong’s picture

FileSize
139.41 KB

I did it and enable the module

kopeboy’s picture

Status: Closed (fixed) » Needs review

I created a module like the examples and could hide (unset) status and sku fields from the table, but I couldn't hide the image field. Is there something more to be done in case of images?

(I can see commerce_product.inline_entity_form.inc code is a bit different there because you have to detect the image field name without knowing it..)

I only have 1 image field, machine name 'product_image', how to unset it?

unset($fields['product_image']); is not hiding it from the table

kopeboy’s picture

I ended up deleting the lines 47 to 98 of the commerce_product.inline_entity_form.inc file but still an horrible solution.

I also need to show a term reference field (the title of the chosen term) in the table, any help on how to do this?

I tried this (not working)

      $fields['my_term_ref_machine_name'] = array(
        'type' => 'field',
        'label' => t('Category'),
        'formatter' => 'taxonomy_term_reference_plain',
        'weight' => 1,
      );

Thanks

jweirather’s picture

Posting this related how-to thread for hiding/modifying IEF fields on standard user forms: https://www.drupal.org/node/2497289

Dr.Osd’s picture

FileSize
84.17 KB

Thanks all for solution!
Additional question: how to show Inline entity form listed fields only if they not empty?

mnico’s picture

Hi, I built a module to help me with this, using view mode. Maybe this can help you

https://www.drupal.org/project/ief_table_view_mode

This still in dev but it works for me well right now

kopeboy’s picture

wow mnico, that is really useful!

Any chance we could do something with the node add/edit form as well?

francescosciamanna’s picture

Thank you mnico!!!

johnhanley’s picture

@mnico, I use to override the IEF table theme in code, but now with Inline Entity Form Table View Mode it's a breeze. The module has a small footprint too. Well done!

johnhanley’s picture

Revisiting this issue in Drupal 8.

I'm adding a taxonomy term to the output of an inline entity table via hook_inline_entity_form_table_fields_alter. The term is outputted as a link, which doesn't make sense in this context. I've hunted high and low, but I can't seem to find an example of how to output the term value as plain text. I found a reference to a 'formatter' attribute for Drupal 7, but I can't find any examples of how to implement it Drupal 8.

Can someone give me a nudge? I figure the answer will be useful to others.

/**
 * Implements hook_inline_entity_form_table_fields_alter().
 */
function custom_inline_entity_form_table_fields_alter(&$fields, $context) {
  if ($context['parent_bundle'] == 'course' && $context['field_name'] == 'field_lesson') {
    foreach ($context ['allowed_bundles'] as $bundle) {
      $fields ['field_segment'] = array(
        'type' => 'field',
        'label' => t('Segment'),
        'weight' => 10,
      );
    }
  }
}
bat2018’s picture

Hi John Hanley,
the solution for me is:

     $fields['field_ananote_tipo_nota'] = [
        'type' => 'field',
        'label' => t('Tipo Nota'),
        'weight' => 102,
        'display_options' => [
          'type' => 'entity_reference_label',
          'settings' => ['link' => FALSE],
        ],
      ];

Ciao!

johnhanley’s picture

Thanks @bat2018. Noted for future reference!

Chris Matthews’s picture

Status: Needs review » Closed (won't fix)

Closing as this support request has been answered.