public function ProductBundleTranslationHandler::entityFormAlter in Commerce Product Bundle 8
Performs the needed alterations to the entity form.
Parameters
array $form: The entity form to be altered to provide the translation workflow.
\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.
\Drupal\Core\Entity\EntityInterface $entity: The entity being created or edited.
Overrides ContentTranslationHandler::entityFormAlter
File
- src/
ProductBundleTranslationHandler.php, line 19
Class
- ProductBundleTranslationHandler
- Defines the translation handler for products bundles.
Namespace
Drupal\commerce_product_bundleCode
public function entityFormAlter(array &$form, FormStateInterface $form_state, EntityInterface $entity) {
parent::entityFormAlter($form, $form_state, $entity);
// Move the translation fieldset to a vertical tab.
if (isset($form['content_translation'])) {
$form['content_translation'] += [
'#group' => 'advanced',
'#attributes' => [
'class' => [
'product-bundle-translation-options',
],
],
];
$form['content_translation']['#weight'] = 100;
// The basic product bundle values will be used, no need for specific elements.
$form['content_translation']['status']['#access'] = FALSE;
$form['content_translation']['name']['#access'] = FALSE;
$form['content_translation']['created']['#access'] = FALSE;
}
$form_object = $form_state
->getFormObject();
$form_langcode = $form_object
->getFormLangcode($form_state);
$translations = $entity
->getTranslationLanguages();
// Change the submit button labels to inform the user that
// publishing/unpublishing won't apply to all translations.
if (!$entity
->isNew() && (!isset($translations[$form_langcode]) || count($translations) > 1)) {
foreach ([
'publish',
'unpublish',
'submit',
] as $button) {
if (isset($form['actions'][$button])) {
$form['actions'][$button]['#value'] .= ' ' . t('(this translation)');
}
}
}
}