Metatag field ignores form element #weight.

Created on 8 September 2016, over 8 years ago
Updated 15 April 2025, about 1 month ago

Installed a new Drupal 8.1.8, installed Metatag. Went to Article content type, added a field Meta Tags (field_meta_tags). While weight of every other form element can be changed via hook_form_alter() by changing the element's #weight attribute, this does not effect the Metatag field.

<?php

function mymodule_form_alter(&$form, \Drupal\Core\Form\FormStateInterface $form_state, $form_id) {
  $form['field_meta_tags']['#weight'] = -200;
}

?>

I have also tried this with doing this with the form pre-render callback. Setting weight does not effect the field weight.

πŸ› Bug report
Status

Active

Version

1.0

Component

Code

Created by

πŸ‡§πŸ‡¬Bulgaria alexrayu

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • πŸ‡§πŸ‡ͺBelgium yoerioptr

    I've created a patch that adds the weight configured in the form display. This way it's possible to move the settings by editing the form display. The only issue is that it uses the "default" form display instead of loading it dynamically.

  • πŸ‡ΊπŸ‡ΈUnited States DamienMcKenna NH, USA
  • πŸ‡ΊπŸ‡ΈUnited States DamienMcKenna NH, USA

    Moving this to the 2.1.x branch.

    Maybe there's a way of inheriting this from the parent class?

  • πŸ‡ΊπŸ‡ΈUnited States DamienMcKenna NH, USA

    I added a breakpoint at the top of MetatagFirehose::formElement() and it shows that $element['#weight'] exists and has a value of 0:

    I changed the field's order on the form display settings for that content type and its weight did not change.

    I examined EntityFormDisplay::buildForm() and after it runs foreach($this->getComponents() the Metatag field's is correct:

    This implies a bug in Form API or maybe the admin theme, not Metatag.

Production build 0.71.5 2024