Hello,

When a CER fields corresponding field is inside an Inline Entity Form, users would probably not want to display that field. I wrote a small sub-module that exposes an option to hide right hand CER fields when inside an Inline Entity Form (no reason for the fields to be displayed at all IMO, but an option is less intrusive).

Config setting

//Josef

CommentFileSizeAuthor
#35 cer-hide-inside-inline-entity-form-2240371-35.patch6.9 KBmonya
#31 cer-2240371-ief-support-31.patch8.06 KBattisan
#23 cer-2240371-ief-support-23.patch6.77 KBphenaproxima
#18 cer-2240371-ief-support-18.patch6.77 KBphenaproxima
#12 cer-hide-inside-inline-entity-form-2240371-12.patch6.47 KBmonya
#8 cer-ief-2240371-unexpected-char.patch829 bytesjgullstr
#7 cer-hide-inside-inline-entity-form-2240371-7.patch4.61 KBjgullstr
#1 cer-hide-inside-inline-entity-form-2240371-1.patch4.21 KBjgullstr
ces_ief_hide_ref.jpg17.52 KBjgullstr
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

jgullstr’s picture

Assigned: jgullstr » Unassigned
Status: Active » Needs review
FileSize
4.21 KB

The patch.

jgullstr’s picture

phenaproxima’s picture

Wow! Thanks @jgullstr. This is a really neat idea. I wouldn't mind committing this into the main CER bundle once it's been reviewed and tested by others.

jgullstr’s picture

Title: Ability to hide Corresponding entity reference fields » Ability to hide Corresponding entity reference fields on Inline Entity Forms

Clarified title.

phenaproxima’s picture

Looking at the code, I have a question -- am I correct that this only supports hiding Entity Reference fields, but not other field types that CER supports? If so, that might be something to consider adding.

EDIT: One way to implement that is to set a no_ief flag on certain field instances in hook_cer_fields_alter(), then use that to hide those instances in IEF. That way you would instantly get support for every type of field that CER deals with.

jgullstr’s picture

Yes you are correct. This is just a quick solution needed for a client project. I imposed this restriction mainly due to convenience, not having to worry about other field types. It could be removed altogether adding a slight overhead. I'll check this out and get back in a bit.

jgullstr’s picture

Here's one attempt at making it field type agnostic. I'm not 100% sure I'm using left/right correctly and that CerField will always be available in this context, but I consider this done from my end. If you or someone else wishes to further improve it, feel free to do so.

//Josef

jgullstr’s picture

phenaproxima’s picture

I committed it by accident a while ago...it needs to be updated to support the alpha7 API.

MrSchoolcraft’s picture

When I have this module (extension) enabled, I cannot edit an entity reference field because I get an error that the _cer_filter_presets($filter) function is not defined.
I am using the alpha7 version. Is there anything I need to do to make it able to use this function? I cannot find its definition anywhere in the CER module.

jgullstr’s picture

Status: Needs review » Needs work
Related issues: +#2332457: function _cer_filter_presets() is undefined

This is broken for current versions.

monya’s picture

adam1’s picture

Since in the latest alpha-release there is this bug in CER inline entity form, i would be so glad if someone could change the patch in order to work with the latest dev version of CER. Thanks!

jgullstr’s picture

If no one else fixes this before, I'll rewrite this when a hard release of 3.x (or at least an API freeze) is available.

phenaproxima’s picture

@adam1: The typo has been fixed in the latest dev. If you're using alpha7, apply this patch:

https://www.drupal.org/files/issues/cer_ief_typo.patch

jgullstr’s picture

The patch is similar to #8 in this thread. Keep in mind that cer_ief does not work at all with versions > alpha5, IIRC.

lucyp’s picture

Hi all, since I am waiting for this feature, I discovered a different way to hide an entity reference field in an IEF. I just wanted to pass this info along in case others are also seeking a solution.

I used the module Hidden Field Widgets https://www.drupal.org/project/hidden_field

Then for that module I applied a couple of patches to allow it to work with entity reference fields.
https://www.drupal.org/node/1821008
https://www.drupal.org/node/2229955

There may be other (better) ways to do it but for me this is working so I am happy.

Meanwhile I'll be glad when this is a regular feature of CER. Thanks to everyone working on the CER module. I really appreciate it.

phenaproxima’s picture

Status: Needs work » Needs review
FileSize
6.77 KB

OK! I did some work on cer_ief and made it use the alpha7 API (i.e., the CerPresetFinder class). I have not tested this at all, but if it works for people here I will promptly commit it to 7.x-3.x.

gdebilde’s picture

Any update on this issue ?

phenaproxima’s picture

@gdebilde: Try the above patch (#18) against the alpha7 version of CER. All it needs is to be tested by the community, and if it works for a few people I will commit it and this long-standing issue will be fixed. ;-)

yasin-ali’s picture

Patch(#18) against alpha7 :: blows up when i click "add new node"... from the log... PDOException: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'field_data_cer_left0.cer_left_value' in 'where clause': SELECT COUNT(*) AS expression FROM (SELECT 1 AS expression FROM {field_data_cer_left} field_data_cer_left0 INNER JOIN {field_data_cer_enabled} field_data_cer_enabled1 ON field_data_cer_enabled1.entity_type = field_data_cer_left0.entity_type AND field_data_cer_enabled1.entity_id = field_data_cer_left0.entity_id WHERE (field_data_cer_left0.cer_left_value LIKE

lucas.constantino’s picture

For anyone interested, I have a working solution made within a custom module. Please, not that I've not tried it as hard as I should, and just want to help anyone who needs this feature right now.

/**
 * Implements hook_inline_entity_form_entity_form_alter(&$entity_form, &$form_state)
 */
function iela_inline_entity_form_entity_form_alter(&$entity_form, &$form_state) {
  module_load_include('inc', 'cer', 'cer.cer');

  $inline_entity_form = $form_state['inline_entity_form'][$entity_form['#ief_id']];

  $parent_entity_type = $inline_entity_form['instance']['entity_type'];
  $parent_bundle      = $inline_entity_form['instance']['bundle'];
  $parent_field_name  = $inline_entity_form['instance']['field_name'];
  $parent_field_info  = field_info_field($parent_field_name);

  $cer_fields = cer_cer_fields();

  // We will check if parent's field responsible for generating this inline
  // entity form has a "cer" definition for it.
  $parent_field_is_cer = FALSE;
  foreach ($cer_fields as $cer_field_name => $cer_field_info) {
    list($cer_field_entity_type, $cer_field_bundle, $cer_field_field_name) = explode(':', $cer_field_name);
    if (
      $cer_field_entity_type == $parent_entity_type &&
      $cer_field_bundle == $parent_bundle &&
      $cer_field_field_name == $parent_field_name
    ) {
      $parent_field_is_cer = TRUE;
      break;
    }
  }

  // Now, we will check if any of the inline entity's fields is a reference
  // field that might point to the parent entity. We will then check if the
  // field also has a "cer" definition.
  if (!$parent_field_is_cer) {
    return; // If parent check failed, no bother to continue processing.
  } else {
    $fields = field_info_instances($entity_form['#entity_type'], $entity_form['#bundle']);
    foreach ($fields as $field_name => $field_instance) {
      $field_info = field_info_field($field_name);
      if (
        $field_info['type'] == 'entityreference' &&
        $field_info['settings']['target_type'] == $parent_entity_type &&
        in_array($parent_bundle, $field_info['settings']['handler_settings']['target_bundles'])
      ) {
        foreach ($cer_fields as $cer_field_name => $cer_field) {
          list($cer_field_entity_type, $cer_field_bundle, $cer_field_field_name) = explode(':', $cer_field_name);
          if (
            $cer_field_entity_type == $entity_form['#entity_type'] &&
            $cer_field_bundle == $entity_form['#bundle'] &&
            $cer_field_field_name == $field_name
          ) {
            // Hide parent field.
            $entity_form[$field_name]['#access'] = FALSE;

            // Remove field required status.
            $entity_form[$field_name][LANGUAGE_NONE]['#required'] = 0;

            if (isset($entity_form[$field_name][LANGUAGE_NONE]['#max_delta'])) {
              $delta = $entity_form[$field_name][LANGUAGE_NONE]['#max_delta'];
              if (is_numeric($delta) && $delta >= 0) {
                for(; $delta >= 0; $delta--) {
                  $entity_form[$field_name][LANGUAGE_NONE][$delta]['target_id']['#required'] = FALSE;
                }
              }
            }
          }
        }
      }
    }
  }
}

I do not have the time right now to look into the patch provided by phenaproxima, but as I've made this solution of mine long ago I believe I can make a new patch based on my previous experience on CER and using phenaproxima's code. I'll try to help as soon as I can ;)

phenaproxima’s picture

This should fix the error in #21. (This patch replaces #18.) Sorry about that!

lucas.constantino’s picture

Nice! I'll try to turn off my custom module and apply your patches when I have the time. Thanks ;)

Khalor’s picture

Status: Needs review » Needs work

The patch in #23 doesn't seem to work (no errors, just doesn't remove the field after selecting 'Hide corresponding entity reference field(s) on form.'). The custom module in #22 does work.

Boobaa’s picture

Arrived here from #2332457: function _cer_filter_presets() is undefined and I can confirm that:

  1. the PHP fatal error is present without the patch in #23,
  2. the patch in #23 solves the PHP fatal error,
  3. the patch in #23 does NOT hide the CER-backed entityreference field in the inline entity form.

I can't say anything about the code in #22 as I haven't tried it.

funkylaundry’s picture

Just for the record I managed to get it to work by applying the patch suggested by @phenaproxima in #23

NancyDru’s picture

trumanru’s picture

The patch #23 doesn't work in CER.
I've being installed the CER 7.x-3.x-dev and tried to edit the IEF entityreference field wich is correctly linked by a CER preset with another entityreference field and I've got the error:
Fatal error: Call to undefined function _cer_filter_presets() in bla-bla-bla/sites/all/modules/cer/extensions/cer_ief/cer_ief.module on line 22

It's true. The text '_cer_filter_presets()' couldn't be found in all other files of modules/cer/* (sub)directories (except in the cer_ief.module file - twice).

NWOM’s picture

#23 sadly doesn't work for me either.

attisan’s picture

implemented all present ideas (thx to lucas.constantino and phenaproxima) into one patch. this one works great for me.

hope it helps.

RAFA3L’s picture

This module work too Field extra widgets

shi99’s picture

Hi,

Patch in #23 worked for me with the latest dev.

Thanks

SocialNicheGuru’s picture

Status: Needs review » Needs work

Edit:
This is not a problem with the patch but the cer_ief module itself. There is no 'function _cer_filter_presets'.

cd cer
grep _cer_filter_preset -d recurse *
extensions/cer_ief/cer_ief.module:    if ($presets = _cer_filter_presets($filter)) {
extensions/cer_ief/cer_ief.module:      foreach (_cer_filter_presets($left_chain) as $preset) {

_cer_filter_presets does not exist anywhere in the 3.x version of the module. It might be available in 2.x

monya’s picture

I fixed problems with patch #23. With this patch we can hide fields in inline_entity_form_single widget too. And also i have changed logic of hiding fields.

delacosta456’s picture

hi

i am facing similar issue in the CER module that didn't have permission settings to hide the checkbox "Synchronize with.." in a form (not in the display).

I tried install the field permission module , but it has an incompatibility.

P2790’s picture

@monya thanks for the fixed patch, very helpful

P2790’s picture

Status: Needs review » Reviewed & tested by the community

The last submitted patch, 8: cer-ief-2240371-unexpected-char.patch, failed testing.

The last submitted patch, 8: cer-ief-2240371-unexpected-char.patch, failed testing.

The last submitted patch, 8: cer-ief-2240371-unexpected-char.patch, failed testing.

The last submitted patch, 8: cer-ief-2240371-unexpected-char.patch, failed testing.

The last submitted patch, 12: cer-hide-inside-inline-entity-form-2240371-12.patch, failed testing.

The last submitted patch, 12: cer-hide-inside-inline-entity-form-2240371-12.patch, failed testing.

The last submitted patch, 12: cer-hide-inside-inline-entity-form-2240371-12.patch, failed testing.

The last submitted patch, 12: cer-hide-inside-inline-entity-form-2240371-12.patch, failed testing.

The last submitted patch, 31: cer-2240371-ief-support-31.patch, failed testing.

The last submitted patch, 31: cer-2240371-ief-support-31.patch, failed testing.

The last submitted patch, 31: cer-2240371-ief-support-31.patch, failed testing.

The last submitted patch, 31: cer-2240371-ief-support-31.patch, failed testing.

puddyglum’s picture

patch #35 worked for me. hoping this can be committed.

  • phenaproxima committed c5c7a89 on 7.x-3.x
    Issue #2240371 by jgullstr, phenaproxima, monya, attisan: Ability to...
phenaproxima’s picture

Status: Reviewed & tested by the community » Fixed

Reviewed and I think it makes sense. Committed and pushed to 7.x-3.x. Thank you!

Status: Fixed » Closed (fixed)

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