From e6f65dbd2facfd3d213cf1118ba4ad30218f8f51 Mon Sep 17 00:00:00 2001 From: Trevor Simonton Date: Sun, 17 Feb 2013 15:07:29 -0700 Subject: Issue #1787838 by tmsimont, mrfelton and malberts: put auto title handling into parent class so nodes and commerce_products behave similarly with auto_entitylabel --- includes/commerce_product.inline_entity_form.inc | 16 +--------------- includes/entity.inline_entity_form.inc | 19 +++++++++++++++++++ includes/node.inline_entity_form.inc | 18 ++---------------- 3 files changed, 22 insertions(+), 31 deletions(-) diff --git a/includes/commerce_product.inline_entity_form.inc b/includes/commerce_product.inline_entity_form.inc index 8438e94..702a6bf 100644 --- a/includes/commerce_product.inline_entity_form.inc +++ b/includes/commerce_product.inline_entity_form.inc @@ -228,21 +228,7 @@ class CommerceProductInlineEntityFormController extends EntityInlineEntityFormCo } // Allow the Automatic Entity Label module to handle the title. - if (module_exists('auto_entitylabel')) { - if (auto_entitylabel_is_needed($product, 'commerce_product')) { - $settings = _auto_entitylabel_get_settings($product, 'commerce_product'); - $setting = auto_entitylabel_get_setting($settings['key']); - if ($setting == AUTO_ENTITYLABEL_ENABLED || ($setting == AUTO_ENTITYLABEL_OPTIONAL && empty($product->{$settings['title']}))) { - if ($setting == AUTO_ENTITYLABEL_OPTIONAL) { - $entity_form['title']['#required'] = FALSE; - } - if ($setting == AUTO_ENTITYLABEL_ENABLED) { - $entity_form['title']['#required'] = FALSE; - $entity_form['title']['#access'] = FALSE; - } - } - } - } + $this->handleAutoTitle($entity_form, $product, 'commerce_product'); // Hide the title field if it is auto-generated. if ($this->settings['autogenerate_title']) { diff --git a/includes/entity.inline_entity_form.inc b/includes/entity.inline_entity_form.inc index f3cc689..2edf1e8 100644 --- a/includes/entity.inline_entity_form.inc +++ b/includes/entity.inline_entity_form.inc @@ -379,4 +379,23 @@ class EntityInlineEntityFormController { public function delete($ids, $context) { entity_delete_multiple($this->entityType, $ids); } + + public function handleAutoTitle(&$entity_form, $entity, $entity_type) { + // Allow the Automatic Entity Label module to handle the title. + if (module_exists('auto_entitylabel')) { + if (auto_entitylabel_is_needed($entity, $entity_type)) { + $settings = _auto_entitylabel_get_settings($entity, $entity_type); + $setting = auto_entitylabel_get_setting($settings['key']); + if ($setting == AUTO_ENTITYLABEL_ENABLED || ($setting == AUTO_ENTITYLABEL_OPTIONAL && empty($entity->{$settings['title']}))) { + if ($setting == AUTO_ENTITYLABEL_OPTIONAL) { + $entity_form['title']['#required'] = FALSE; + } + if ($setting == AUTO_ENTITYLABEL_ENABLED) { + $entity_form['title']['#required'] = FALSE; + $entity_form['title']['#access'] = FALSE; + } + } + } + } + } } diff --git a/includes/node.inline_entity_form.inc b/includes/node.inline_entity_form.inc index d3582c2..d87a76e 100644 --- a/includes/node.inline_entity_form.inc +++ b/includes/node.inline_entity_form.inc @@ -43,21 +43,7 @@ class NodeInlineEntityFormController extends EntityInlineEntityFormController { ); // Allow the Automatic Entity Label module to handle the title. - if (module_exists('auto_entitylabel')) { - if (auto_entitylabel_is_needed($node, 'node')) { - $settings = _auto_entitylabel_get_settings($node, 'node'); - $setting = auto_entitylabel_get_setting($settings['key']); - if ($setting == AUTO_ENTITYLABEL_ENABLED || ($setting == AUTO_ENTITYLABEL_OPTIONAL && empty($node->{$settings['title']}))) { - if ($setting == AUTO_ENTITYLABEL_OPTIONAL) { - $entity_form['title']['#required'] = FALSE; - } - if ($setting == AUTO_ENTITYLABEL_ENABLED) { - $entity_form['title']['#required'] = FALSE; - $entity_form['title']['#access'] = FALSE; - } - } - } - } + $this->handleAutoTitle($entity_form, $node, 'node'); $langcode = entity_language('node', $node); field_attach_form('node', $node, $entity_form, $form_state, $langcode); @@ -75,7 +61,7 @@ class NodeInlineEntityFormController extends EntityInlineEntityFormController { // Pre-set the title before we submit so that it's visible. auto_entitylabel_set_title($entity_form['#entity'], 'node'); } - + node_submit($entity_form['#entity']); $child_form_state = form_state_defaults(); $child_form_state['values'] = drupal_array_get_nested_value($form_state['values'], $entity_form['#parents']); -- 1.7.4.msysgit.0