Problem/Motivation

I recently updated a project from Drupal 8.9 to Drupal 10. The old versions used the old version of Google Tag Manager module and the new one uses now Google Tag 2.0.2. I enabled the option to create multiple containers than I add a new container but there no option to edit label or machine name. They are assigned automatically.

Image attached to see the current status.

Steps to reproduce

  1. Enable the module Google Tag
  2. Enable the option "Allow multiple Tag Containers" on the Advanced Tab under settings: admin/config/services/google-tag/settings
  3. On the Tab "Additional Tags" create another container or edit the existent one.
  4. There is no options to change the label or machine name (by creating a new container).
  5. By saving the container the laben an machine name have been added automatically.

Proposed resolution

Add fields to be able to edit the label and machine name (by creating a new container)

User interface changes

  • A new field label
  • A new field machine name

Issue fork google_tag-3420716

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

juagarc4 created an issue. See original summary.

japerry’s picture

This is by design. The machine name and label are auto-generated because requiring users to create them is an additional unneeded step. Is there a reason why they needed to be edited specifically?

Note -- if there is a need to change them, it can be done manually with the config entity. Since they really shouldn't be changed by end users, I'd suggest going this route instead of changing the UI.

japerry’s picture

Status: Active » Postponed (maintainer needs more info)
juagarc4’s picture

Hi japerry,

Thanks for the answer.

Since you can use more containers and more IDs per container, I think it make sense, so that the label and machine name can be used as a kind of categories.

One use case I have for that right now is the use of this module in combination with Domain. Since I'm using different containers per Domain, it would be useful to put the domain name in the label. In this way is easier to identify what need to be changed, deleted, etc. without having to edit all of them.
Moreover the use of a customized machine name in the same way of the label would make easier to get information of the container programatically.

Note: Changing the config entity can be easy done by programmers, but normally the users authorized to change this configuration, don't have the knowledge for that. In this case a change in the UI would be quite appreciated.

guiu.rocafort.ferrer’s picture

IMO, it would be useful to be able to change the Label, but the machine_name should not be possible to be changed. This allows to add more meaningful names to the containers, rather than having to remember the container ids. This behaviour is widely used in Drupal Core, for instance, if you create a content type, then you can modify the label, but the machine_name stays the same.

There is already a label field in the entity type google_tag_container. So this would only require to add the textfield element in the edit form.
I will create a issue fork and give it a go, should be fairy easy to do.

guiu.rocafort.ferrer’s picture

I added the label field to the edit form, but i am taking in account the following cases, to avoid disrupting existing workflows and add extra steps when creating a tag container:

  • If the label is left empty, the first tag ID will be used as the label, as before. I added a little description to clarify the behaviour
  • If the label is specified, then this one will be used instead of the first tag ID.

The machine_name is still generated in the same way, and it cannot be changed.

I think this would be a great usability improvement for the module, because it allows to add friendly readable names to containers. If you have several containers, it can become complicated to know which is which.

juagarc4’s picture

I'm agree with this approach @guiu. The possibility of changing of the machine name is really not necessary.
I'll try to test it in the next days.
Thanks!

guiu.rocafort.ferrer’s picture

Status: Postponed (maintainer needs more info) » Needs review

Changing issue status to needs review.

japerry’s picture

Status: Needs review » Fixed

Agreed on the label. The machine name stays as it is: other config refers to it, and core config entities don't allow renaming one either. That part is won't fix.

  • @guiu.rocafort.ferrer's two commits from the issue fork are in MR !162 plus follow up commits:
  • The label is optional on both the add and edit forms. A blank label falls back to the first Google Tag ID, so containers created without one (recipes, config import) can still be saved.
  • The label now sits under Advanced settings instead of at the top of the form, since most sites won't need it.
  • Advanced settings now starts collapsed. It was meant to all along, but as a fieldset it couldn't collapse.
  • The label is limited to 255 characters, and a label of only spaces is treated as blank.
  • Added TagContainerFormTest coverage for a custom label, the empty and blank fallback on add and edit, renaming a container while its machine name stays the same, and the label's position in the collapsed Advanced settings.

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

  • japerry committed 576e1e01 on 2.0.x
    fix: #3420716 Let the container label be edited