Quantcast
Channel: Question and Answer » inline-entity-form
Viewing all 16 articles
Browse latest View live

form_alter: Inline entity Form

$
0
0

I am using IEF and all is well…until I try ad implement hook_form_alter() and when I access the form via IEF UI (as opposed to directly modifying the entity) none of the changes I make appear to take effect.

I see everything is posted to a ajax/system as well as pulled from when assembling the form…

Is it not possible to hide form elements from the IEF as I would when directly hooking?

Any ideas?

Each line item has a price field which I need to iterate and sum and the apply to the root node. Figured as this module was used in commerce this would be standard practice.


Inline Entity Form Vertical tabs

$
0
0

According to the author of Inline Entity form, there is a way to customize with hook_inline_entity_form_entity_form_alter to be able to set vertical tabs that could be rendered despite the fact that IEF doesn’t render vertical tabs.

But because I manually create the form I can manipulate instantly. But what do I have to write that the form is rendered? Do I have to adjust the js file from misc?

Here is what I have and what is also shown by devel, but not rendered:

/**
* Overrides EntityInlineEntityFormController::entityForm().
*/
public function entityForm($entity_form, &$form_state) {
$info = entity_get_info($this->entityType);
$entity = $entity_form['#entity'];

$entity_form['furnished'] = array(
   '#type' => 'vertical_tabs',
);
$entity_form ['furn_basis'] = array(
    '#type' => 'fieldset',
    '#title' => t('House-Appartment-Basics'),
    '#weight' => 2,
    '#group' => 'furnished',
    '#collapsible' => TRUE,
    '#collapsed' => FALSE,
);
...
}

The fieldsets are collapsible, but not in the vertical tabs group…

THX in advance,

maen

How do I pull a field value from a form field in to my inline entity form?

$
0
0

I’m trying to do something which I would think is fairly simple, but I’m just stumped right now, hoping somebody can help.

I have an entity called ‘page’, and in that entity I have inline entities called ‘subpages’. Both of these entities have a field called ‘group_reference’ which tells the entity what ‘group’ the entities belong to.

Basically what I want to do is automatically change the group_reference form field value in my inline entity form to match the group reference in my page form. So far, I’m using inline_entity_form_entity_form_alter to access the inline entity forms values. I’m able to adjust the value to an arbitrary value like this:

function MYMODULE_inline_entity_form_entity_form_alter(&$entity_form, &$form_state) {
  if ($entity_form['#bundle'] == 'subpage') {
    $entity_form['field_group_reference']['und']['0']['#default_value']=X;
  }
}

X being the group id.

So the next step I want is to pull in the group id from the page group_reference field which is already set. That way, they will always match (the user is not able to change this value, it all should be done behind the scenes).

I’ve tried to include in my module a function that pulls out the value from the field, but I just can’t seem to make it work:

function MYMODULE_grab_group_reference(&$form, &$form_state) {
    return $form['field_group_reference']['und']['#value'];
}

function MYMODULE_inline_entity_form_entity_form_alter(&$entity_form, &$form_state) {
  if ($entity_form['#bundle'] == 'subpage') {
    $groupid=MYMODULE_grab_group_reference();
    $entity_form['field_group_reference']['und']['0']['#default_value']=$groupid;
  }
}

I’ve tried a bunch of different variations. Am I not targeting my values correctly? Is this just an improper way to do it? I’m flummoxed. Any help would be greatly appreciated! Thanks!

Alternate title replacing Product Title

$
0
0

This is a combobox showing a group of product referenced.

enter image description here

I have created an extra field in product list, short_title. How do I replace the Product Title with short_title? i.e. Chicken, Turkey, Pork, … Is this possible?

I’ve also tried Inline Form Entity. The YouTube tutorial: http://youtu.be/glRM_NzNVTA?t=5m3s : When the host edited the Variation Title, the Product Title remained unchanged. However, when I do it, the Product Title changed. Is this by design or the host was using an older version of Inline Entity Form?

I know that we can create attributes, but having a variety of product types complicates the form. All I wanted: one product type and just reference a group of product in product display.

The Product Title is too long in combo, but I can’t shortened that because it’s important as line-item title.

Any idea or workaround?

Inline entity form shows a content type select list

$
0
0

I am using Inline entity form for a non-commerce project.
The settings are:Widget:multiple values,Node:Allow users to add existing content.
Mode:Views:Filter by Entity reference view.So I have created an Entity reference view to show only nodes that have been created by the user.
The issue is:When looking at the Inline entity form to create or add existing content,there is a dropdown with all the content types of the site.This only appeared when I change the mode to Views:Filter by Entity reference view
How can I remove that?
thanks
See image attached

enter image description here

Can not get inline entity form to work with commerce product and room rooms_unit_type

$
0
0

I have added an Entity Reference field to a Commerce : Product Type that uses the Inline Entity Form widget. The reference is to the Bookable Unit Type bundle that is created by the Rooms (more specifically, the Rooms Unit module which comes with Rooms).

I have attempted to add the following to function inline_entity_form_entity_info_alter(&$entity_info)

$entity_info['rooms_unit_type']['inline entity form'] = array(
  'controller' => 'CommerceLineItemInlineEntityFormController',
);

The entity reference form never shows when creating new or editing a product. If I use the autocomplete widget, I am able to select an entity (although that does me no good).

Thanks for any help.

Inline Entity Form – start with first new node open

$
0
0

My install is using Inline Entity Forms and I would like it so that when a user visits the create node page, the inline entity form starts already visible but with all fields empty and ready to be created (no need to click “Add Node”).

I would like to implement either a module or tpl file in my theme to achieve this. Please can you advise on how to go about it.

I’ve used this patch https://www.drupal.org/node/2225675 but it only works when editing existing content.

Add referenced entity if none was found using Inline Entity Form autocomplete

$
0
0

I tried to look for a solution and wasn’t successful: Is there any module or other solution for Drupal 7, that would extend Inline Entity Form to offer creation of new entity if none was found using autocomplete widget? Yes, I can cancel the form and create new entity, but this isn’t straightforward. I also found some discussions about this, but no solution integrated with IEF:

Does anything like this exist?


Inline Entity Form – IEF – Hook Form Alter – Ordering

$
0
0

I’ve got a module that I’m developing (I’m admittedly new to module development) – where I’m appending a date to the IEF fields displayed. It looks like this so far.

function customized_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=='rate') {
    $is_rate = TRUE;
  }
}
if ($is_rate) {
  $fields['field_rate_dates'] = array(                   // This part adds the body field with a label 'description'
    'type' => 'field',
    'label' => t('Dates'),
    'weight' => 101,
  );
}

}

So far – so good. I want to display the relevant dates in field “field_rate_dates” – and they’re displaying in the table.

Where I’m getting hung up is – IEF appears to be rendering the order randomly. I would like to output the order by the date I’m appending there (“field_rate_dates”) ASC – and I’ve been unable to find any hints on how to get that done.

Any help would be greatly appreciated :)

New product variation form for a new user

$
0
0

I want to display a new product variation form for an existing product to a new user where that user can create a new product variation for an existing product and the user will not be able to see the variations created by other users for that product. I want that “Add Product Variation” button for a new user who has not created the product.

I try to find a way to get this done with inline entity form module functionality as the product variation field is generated by inline entity form module.

Please suggest.

Ability to create forms for each node in Drupal 7

$
0
0

I am creating articles in which I want to ask, on each article, that whether the it was helpful to read or not.

The user would have two option boxes:-

© Yes

© No

One of these will be selected and the form should be submitted through JQuery. It should be recorded with each node so that we would also know how many total users found this helpful too?

Any idea how would I achieve that?

I wish it could be achieved through Flags or Rating but I haven’t been able to do so.

Thanks a lot

Inline Entity Form – How to change label for the EDIT button and REMOVE button

$
0
0

I try to modify the ‘Edit’ and ‘Remove’ label on the buttons displayed in the IEF table.
I can modify the ‘Add new node’ buttons with the code bellow

function MY_MODULE_form_alter(&$form, &$form_state, $form_id) {
  if ($form_id == 'CONTENTTYPE_node_form') {
    /*
    * Modify the Add node button when it's the first one
    */
    $form['MY_FIELD']['und']['form']['actions']['ief_add_save']['#value'] = t('CUSTOM TEXT');
    /*
    * Modify the Add node button when there is at least one node
    */
    $form['MY_FIELD']['und']['actions']['ief_add']['#value'] = t('CUSTOM TEXT');
  }
}

But I can’t make it work for the Edit or Remove buttons

For the Edit button, I tried to add in this function:

$form['MY_FIELD']['und']['form']['actions']['ief_entity_edit']['#value'] = t('CUSTOM TEXT');

Doesn’t work

$form['MY_FIELD']['und']['actions']['ief_entity_edit']['#value'] = t('CUSTOM TEXT');

Doesn’t work either

Any idea ?

How can I make hook_field_group_build_pre_render_alter Inline Entity Form compatible?

$
0
0

I’m using hook_field_group_build_pre_render_alter to conditionally hide field group based on value of other field. It works fine on standard Drupal node edit form, but fails, when the node is opened inside IEF form. Is there a way to make this functionality compatible?

EDIT: When I try to use this in IEF form, following error is displayed in browser console:

Empty String passed to getElementById()

inline entity form prevent reference entities to be created if the referenced form not successfully validated

$
0
0

I need to make created nodes via inline entity form not created or updated if the main form returns form error.

The main reason for that is we make custom validation by doing some computation on child nodes that may return form error and we need prevent add or update the child nodes if the custom criteria didn’t pass, the child nodes must be edited to match criteria or not being available in the system at all to prevent useless content.

Code:

function custom_form_alter(&$form, DrupalCoreFormFormStateInterface $form_state, $form_id) {
if($form_id == 'node_takleef_form' || $form_id == 'node_takleef_edit_form'){
$form['#validate'][] = 'custom_takleef_validate';
  }
}

function custom_takleef_validate(&$form, DrupalCoreFormFormStateInterface $form_state) {
  $form_state_values = $form_state->getValues();

  if($form_state->getTriggeringElement()['#parents'][0] == 'publish'){
  //DO some logic here
   $form_state->setErrorByName('field_hours', 'Sorry the hours maximum value per year is 10');
  // HERE I NEED TO STOP SAVING CHILD NODES
  }

Inline entity form complex and cardinatlity

$
0
0

I am adding an ief type field to my form with the following

    $form['inline_entity_form'] = [
        '#type' => 'inline_entity_form',
        '#op' => 'add',
        '#entity_type' => 'my_ent_type',
        '#bundle' => 'my_bundle',
    ];

I am sure this is something under my nose that i am missing but how do i force this to complex and set a cardinality for this instance?

Grateful for any pointers
Mathew


automatic node title with entity reference and inline entity form

$
0
0

I am trying to make a content type that would contain references to nodes by means of inline entity form. The child nodes are to be created only by means of inline entity form.
I want the title field of the child node to be created automatically, so it gets the form of [parent_node_title] [taxonomy_term_field].
I’ve found two modules: Automatic Nodetitle and Auto Entity Label. I’ve even found some discussions about the problem with patches that are supposed to solve that problem (like here).
Despite that, it does not work. I think I am missing something basic.

Viewing all 16 articles
Browse latest View live