In the Entity Translation settings (admin/config/regional/entity_translation), if you check "Hide shared elements on translation forms" for Commerce Product, the "Save product" button and Cancel link disappear from the form when adding or editing a product translation.

Steps to reproduce

  1. Fresh install of Drupal 7.17.
  2. Enable Entity Translation 7.x-1.0-beta2+4-dev, Commerce 7.x-1.4+22-dev (enabling Product and Product UI).
  3. Add a language at admin/config/regional/language.
  4. Enable Entity Translation for Commerce Product entities at admin/config/regional/entity_translation, checking the "Hide shared elements on translation forms" option.
  5. Enable Entity translation for the default product type at admin/commerce/products/types/product/edit.
  6. Add a text field to the default product type at admin/commerce/products/types/product/fields.
  7. Add a product.
  8. Add a translation for this product. No button is shown to save the translation.

Commerce Product Entity Translation missing button.png

Relevant code from entity_translation

public function entityFormSharedElements(&$element) {
  static $ignored_types, $shared_labels, $access;
  if (!isset($ignored_types)) {
    $ignored_types = array_flip(array('actions', 'value', 'hidden', 'vertical_tabs', 'token'));
  }
…

Patch against 7.x-1.x-dev which changes the 'actions' element type from container to actions and resolves the issue.

Comments

rszrama’s picture

Title: Commerce Product form incompatible with Entity Translation "Hide shared elements on translation forms" option » Support Entity Translation "Hide shared elements on translation forms" option
Category: bug » feature

Hmm, if I'm not mistaken, there is no form element type #actions. How do other modules supporting this feature of Entity Translation work?

bojanz’s picture

Sure there is, from system_element_info():

  $types['actions'] = array(
    '#theme_wrappers' => array('container'),
    '#process' => array('form_process_actions', 'form_process_container'),
    '#weight' => 100,
  );
star-szr’s picture

rszrama’s picture

Wow. Totally undocumented on api.d.o. :-/

We may as well make this a patch to use #actions anywhere we're just using a #container called actions.

star-szr’s picture

StatusFileSize
new3.46 KB

The actions element is documented under "Special Elements" in the Form API reference. I just learned about it today though :)

We may as well make this a patch to use #actions anywhere we're just using a #container called actions.

I like that idea. Updated patch to set all $form['actions'] to #type = actions.

Remaining '#type' => 'container' lines:

grep -nr -C2 "=> 'container'"

modules/cart/commerce_cart.module-1891-    // Add the line item's fields to a container on the form.
modules/cart/commerce_cart.module-1892-    $form['line_item_fields'] = array(
modules/cart/commerce_cart.module:1893:      '#type' => 'container',
modules/cart/commerce_cart.module-1894-      '#parents' => array('line_item_fields'),
modules/cart/commerce_cart.module-1895-      '#weight' => 10,
--
modules/checkout/includes/commerce_checkout.checkout_pane.inc-83-  // Use a container to hide completion message settings unless overriden.
modules/checkout/includes/commerce_checkout.checkout_pane.inc-84-  $form['container'] = array(
modules/checkout/includes/commerce_checkout.checkout_pane.inc:85:    '#type' => 'container',
modules/checkout/includes/commerce_checkout.checkout_pane.inc-86-    '#access' => filter_access(filter_format_load($text_format)),
modules/checkout/includes/commerce_checkout.checkout_pane.inc-87-    '#states' => array(
--
modules/order/includes/commerce_order.checkout_pane.inc-58-    // Otherwise add an order e-mail address field to the form.
modules/order/includes/commerce_order.checkout_pane.inc-59-    $pane_form['login'] = array(
modules/order/includes/commerce_order.checkout_pane.inc:60:      '#type' => 'container',
modules/order/includes/commerce_order.checkout_pane.inc-61-      '#prefix' => '<div id="account-login-container">',
modules/order/includes/commerce_order.checkout_pane.inc-62-      '#suffix' => '</div>',
star-szr’s picture

StatusFileSize
new3.54 KB

Actually we can get rid of the attributes lines as well, that's covered by form_process_actions().

star-szr’s picture

Hate to say it but I think we can probably get rid of some of the #weight lines as well. system_element_info() (in @bojanz's comment) sets a default weight of 100, only commerce_product_product_form() sets a weight higher than 100.

star-szr’s picture

StatusFileSize
new2.09 KB
new4.67 KB

I left the #weight = 40 ones alone, this patch flattens the arrays of the two $form actions that had a weight of 100 and moves them before the $form['actions']['submit'] lines. Sorry about all the patches :)

star-szr’s picture

Title: Support Entity Translation "Hide shared elements on translation forms" option » Update containers with a class of form-actions to use FAPI actions element
Component: Internationalization » Developer experience

And this should probably get re-titled and re-filed, not sure about DX but i18n doesn't seem right anymore.

star-szr’s picture

StatusFileSize
new587 bytes
new5.24 KB

Found one form that has a $form['actions']['submit'] but doesn't declare $form['actions']. commerce_payment_order_transaction_add_form() should probably declare the actions element as well. One more patch for the road.

rszrama’s picture

Rockin' my world! Thanks for all the updates. Haven't had a chance to review yet, but I'm lookin' forward to it. : )

star-szr’s picture

#10: commerce-1862942-10.patch queued for re-testing.

star-szr’s picture

Assigned: Unassigned » star-szr

Assigning so I can keep this on my radar. Patch still applies with an offset.

rszrama’s picture

Assigned: star-szr » Unassigned
Status: Needs review » Fixed

Looks great - thanks for sticking with this, and welcome to the committers log. : )

star-szr’s picture

Good news, thank you!

Status: Fixed » Closed (fixed)

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