When the theme used for the site uses utility classes (like Bootstrap 5 or Tailwind CSS), it's useful to be able to add CSS classes to the registration link without preprocessing.

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

milos.kroulik created an issue. See original summary.

milos.kroulik’s picture

Status: Active » Needs work

Basic working version is in the MR, I still need to fix the issue mentioned above and check if link rendering is handled correctly.

milos.kroulik’s picture

Status: Needs work » Needs review

Should be ready for review now.

milos.kroulik’s picture

Assigned: milos.kroulik » Unassigned
john.oltman’s picture

Thanks for this enhancement. A couple of things:

* The pipeline is throwing phpcs warnings. Look like easy fixes.
* We'll need a test added to RegistrationLinkFormatterTest.php (in tests/src/Kernel/Plugin/Field/Formatter)

john.oltman’s picture

Status: Needs review » Needs work
joville’s picture

We are often using this great module in our projects and have the need to customize the links in theming. Therefore I am asking wether it would be more flexible to use a link render array like the following for twig link function usage in Theming? There is sometime a need to do this in theme to allow for example to add a fixed default class and adding for example modifier classes in the field formatter. This would enhance the use cases much more.

                $label = $this->getSetting('label') ?: $registration_type->label();
                $class[] = $this->getSetting('css_classes');
                $elements[] = [
                  '#title' => $label,
                  '#type' => 'link',
                  '#url' =>$url,
                  '#attributes' => [
                    'class' => $class,
                  ],
                ];

instead of (Line 155):

                $label = $this->getSetting('label') ?: $registration_type->label();
                $class[] = $this->getSetting('css_classes');
                $link = Link::fromTextAndUrl($label, $url)->toRenderable();
                $link['#attributes'] = ['class' => $class];
                $elements[] = [
                  '#markup' => $this->renderer->renderInIsolation($link),
                ];
joville’s picture

There is a patch file for the above comment in #8

john.oltman’s picture

Thanks @joville I think that makes sense - the "toRenderable" function does exactly what you are proposing - except your way removes the need to render the link right away, so it simplifies the change (we can then remove the code related to rendering). And as you mentioned delaying the rendering allows for more theme flexibility for the link.

john.oltman’s picture

Assigned: Unassigned » john.oltman

john.oltman’s picture

Assigned: john.oltman » Unassigned
Status: Needs work » Fixed
john.oltman’s picture

joville’s picture

@john.oltman Great! Thank you very much for accepting my proposal and for the hint! I have tested the last merge and it does do the job as expected.

Status: Fixed » Closed (fixed)

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