Add "Set Title" action.

Created on 1 November 2023, over 1 year ago

Problem

  • I'm unable to change the title of the page
  • Example: taxonomy core editing interface has titles that are not very descriptive, exclude vocabulary and can be confusing to a client.

Proposed solution

Feature request
Status

Active

Version

2.0

Component

Code

Created by

🇦🇺Australia VladimirAus Brisbane, Australia

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

Merge Requests

Comments & Activities

  • Issue created by @VladimirAus
  • Status changed to Needs review over 1 year ago
  • 🇦🇺Australia VladimirAus Brisbane, Australia

    New action added.

  • Merge request !393Issue #3398533: Add "Set Title" action → (Open) created by VladimirAus
  • Open in Jenkins → Open on Drupal.org →
    Core: 10.1.x + Environment: PHP 8.1 & MySQL 8
    last update over 1 year ago
    297 pass
  • Pipeline finished with Failed
    over 1 year ago
    Total: 338s
    #43067
  • Open in Jenkins → Open on Drupal.org →
    Core: 10.1.x + Environment: PHP 8.1 & MySQL 8
    last update over 1 year ago
    297 pass
  • Pipeline finished with Success
    over 1 year ago
    #43255
  • Status changed to Needs work over 1 year ago
  • 🇩🇪Germany jurgenhaas Gottmadingen

    This looks like a great improvement, thanks @VladimirAus for the contribution. The tests are reporting 3 issues, 2 of which a caused by the merge request. The third one is from a different code fraction and should be gone after you've rebased the fork.

  • Pipeline finished with Failed
    over 1 year ago
    Total: 434s
    #56215
  • Pipeline finished with Failed
    over 1 year ago
    #56225
  • Pipeline finished with Failed
    over 1 year ago
    Total: 257s
    #56229
  • Pipeline finished with Success
    over 1 year ago
    Total: 414s
    #56231
  • Open in Jenkins → Open on Drupal.org →
    Core: 10.1.x + Environment: PHP 8.1 & MySQL 8
    last update over 1 year ago
    297 pass
  • Open in Jenkins → Open on Drupal.org →
    Core: 10.1.x + Environment: PHP 8.1 & MySQL 8
    last update over 1 year ago
    297 pass
  • 🇦🇺Australia jannakha Brisbane!

    @VladimirAus:
    Weird local vs prod environment issue:
    Local works, production throws warnings/errors and crashes out:

    Error: Call to a member function replaceClear() on null in Drupal\eca_base\Plugin\Action\Title->execute() (line 44 of /app/web/modules/contrib/eca/modules/base/src/Plugin/Action/Title.php).

    Warning: Undefined property: Drupal\eca_base\Plugin\Action\Title::$tokenService in Drupal\eca_base\Plugin\Action\Title->execute() (line 44 of /app/web/modules/contrib/eca/modules/base/src/Plugin/Action/Title.php)
    #0 /app/web/core/includes/bootstrap.inc(164): _drupal_error_handler_real(2, 'Undefined prope...', '/app/web/module...', 44)
    #1 /app/web/modules/contrib/eca/modules/base/src/Plugin/Action/Title.php(44): _drupal_error_handler(2, 'Undefined prope...', '/app/web/module...', 44)
    #2 /app/web/modules/contrib/eca/src/Entity/Objects/EcaAction.php(102): Drupal\eca_base\Plugin\Action\Title->execute(NULL)
    #3 /app/web/modules/contrib/eca/src/Processor.php(188): Drupal\eca\Entity\Objects\EcaAction->execute(Object(Drupal\eca\Entity\Objects\EcaAction), Object(Drupal\eca_form\Event\FormBuild), Array)
    #4 /app/web/modules/contrib/eca/src/Processor.php(190): Drupal\eca\Processor->executeSuccessors(Object(Drupal\eca\Entity\Eca), Object(Drupal\eca\Entity\Objects\EcaAction), Object(Drupal\eca_form\Event\FormBuild), Array)
    #5 /app/web/modules/contrib/eca/src/Processor.php(146): Drupal\eca\Processor->executeSuccessors(Object(Drupal\eca\Entity\Eca), Object(Drupal\eca\Entity\Objects\EcaEvent), Object(Drupal\eca_form\Event\FormBuild), Array)
    #6 /app/web/modules/contrib/eca/src/EventSubscriber/EcaBase.php(76): Drupal\eca\Processor->execute(Object(Drupal\eca_form\Event\FormBuild), 'eca.form.build')
    #7 [internal function]: Drupal\eca\EventSubscriber\EcaBase->onEvent(Object(Drupal\eca_form\Event\FormBuild), 'eca.form.build', Object(Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher))
    #8 /app/web/core/lib/Drupal/Component/EventDispatcher/ContainerAwareEventDispatcher.php(111): call_user_func(Array, Object(Drupal\eca_form\Event\FormBuild), 'eca.form.build', Object(Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher))
    #9 /app/web/modules/contrib/eca/src/Event/TriggerEvent.php(73): Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch(Object(Drupal\eca_form\Event\FormBuild), 'eca.form.build')
    #10 /app/web/modules/contrib/eca/modules/form/src/HookHandler.php(47): Drupal\eca\Event\TriggerEvent->dispatchFromPlugin('form:form_build', Array, Object(Drupal\Core\Form\FormState))
    #11 /app/web/modules/contrib/eca/modules/form/eca_form.module(25): Drupal\eca_form\HookHandler->alter(Array, Object(Drupal\Core\Form\FormState))
    #12 /app/web/core/lib/Drupal/Core/Extension/ModuleHandler.php(545): eca_form_form_alter(Array, Object(Drupal\Core\Form\FormState), 'taxonomy_term_r...')
    #13 /app/web/core/lib/Drupal/Core/Form/FormBuilder.php(840): Drupal\Core\Extension\ModuleHandler->alter('form', Array, Object(Drupal\Core\Form\FormState), 'taxonomy_term_r...')
    #14 /app/web/core/lib/Drupal/Core/Form/FormBuilder.php(284): Drupal\Core\Form\FormBuilder->prepareForm('taxonomy_term_r...', Array, Object(Drupal\Core\Form\FormState))
    #15 /app/web/core/lib/Drupal/Core/Entity/EntityFormBuilder.php(48): Drupal\Core\Form\FormBuilder->buildForm(Object(Drupal\taxonomy\TermForm), Object(Drupal\Core\Form\FormState))
    #16 /app/web/core/modules/taxonomy/src/Controller/TaxonomyController.php(26): Drupal\Core\Entity\EntityFormBuilder->getForm(Object(Drupal\taxonomy\Entity\Term))
    #17 [internal function]: Drupal\taxonomy\Controller\TaxonomyController->addForm(Object(Drupal\taxonomy\Entity\Vocabulary))
    #18 /app/web/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(123): call_user_func_array(Array, Array)
    #19 /app/web/core/lib/Drupal/Core/Render/Renderer.php(592): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}()
    #20 /app/web/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(124): Drupal\Core\Render\Renderer->executeInRenderContext(Object(Drupal\Core\Render\RenderContext), Object(Closure))
    #21 /app/web/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(97): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext(Array, Array)
    #22 /app/vendor/symfony/http-kernel/HttpKernel.php(181): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}()
    #23 /app/vendor/symfony/http-kernel/HttpKernel.php(76): Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object(Symfony\Component\HttpFoundation\Request), 1)
    #24 /app/web/core/lib/Drupal/Core/StackMiddleware/Session.php(58): Symfony\Component\HttpKernel\HttpKernel->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
    #25 /app/web/core/lib/Drupal/Core/StackMiddleware/KernelPreHandle.php(48): Drupal\Core\StackMiddleware\Session->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
    #26 /app/web/core/modules/page_cache/src/StackMiddleware/PageCache.php(106): Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
    #27 /app/web/core/modules/page_cache/src/StackMiddleware/PageCache.php(85): Drupal\page_cache\StackMiddleware\PageCache->pass(Object(Symfony\Component\HttpFoundation\Request), 1, true)
    #28 /app/web/core/modules/ban/src/BanMiddleware.php(50): Drupal\page_cache\StackMiddleware\PageCache->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
    #29 /app/web/core/lib/Drupal/Core/StackMiddleware/ReverseProxyMiddleware.php(48): Drupal\ban\BanMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
    #30 /app/web/core/lib/Drupal/Core/StackMiddleware/NegotiationMiddleware.php(51): Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
    #31 /app/web/core/lib/Drupal/Core/StackMiddleware/StackedHttpKernel.php(51): Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
    #32 /app/web/core/lib/Drupal/Core/DrupalKernel.php(704): Drupal\Core\StackMiddleware\StackedHttpKernel->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
    #33 /app/web/index.php(19): Drupal\Core\DrupalKernel->handle(Object(Symfony\Component\HttpFoundation\Request))
    #34 {main}

  • 🇩🇪Germany jurgenhaas Gottmadingen

    That sounds like you're using ECA 1.1 on production, while this patch only works with the 2.0.x release.

  • 🇩🇪Germany jurgenhaas Gottmadingen

    @VladimirAus Any chance to address my questions in #6?

  • 🇦🇺Australia VladimirAus Brisbane, Australia

    @jurgenhaas Yep, I'm planning to address it in the coming weeks.
    No ETA though, sorry.

  • 🇩🇪Germany jurgenhaas Gottmadingen
  • Pipeline finished with Success
    12 months ago
    Total: 216s
    #138476
  • Pipeline finished with Skipped
    12 months ago
    #138559
  • 🇩🇪Germany jurgenhaas Gottmadingen

    @VladimirAus are you coming to DrupalCon Portland? We could then probably address this there.

  • 🇩🇪Germany jurgenhaas Gottmadingen
  • Pipeline finished with Failed
    10 months ago
    Total: 485s
    #197217
  • 🇩🇪Germany jurgenhaas Gottmadingen

    @VladimirAus hope you don't mind a friendly ping.

  • 🇦🇺Australia VladimirAus Brisbane, Australia

    Still here. Stuck in a rut of Drupal 11 and then jumping on this guy.
    @jurgenhaas feel free to ping me.

  • Pipeline finished with Failed
    8 months ago
    #244601
  • 🇩🇪Germany jurgenhaas Gottmadingen

    Ping ;-)

  • Pipeline finished with Failed
    7 months ago
    Total: 536s
    #266139
  • Pipeline finished with Failed
    5 months ago
    Total: 447s
    #331074
  • Pipeline finished with Failed
    5 months ago
    Total: 457s
    #331098
  • Pipeline finished with Success
    5 months ago
    Total: 462s
    #331147
  • Pipeline finished with Success
    5 months ago
    Total: 448s
    #331166
  • 🇩🇪Germany jurgenhaas Gottmadingen

    I've rebased the MR to the latest dev branch. @VladimirAus maybe this is an issue to be addressed in Singapor?

  • Pipeline finished with Failed
    4 months ago
    #362443
  • Pipeline finished with Canceled
    4 months ago
    Total: 76s
    #362459
  • Pipeline finished with Success
    4 months ago
    Total: 472s
    #362460
  • Pipeline finished with Canceled
    3 months ago
    Total: 79s
    #391762
  • Pipeline finished with Success
    3 months ago
    Total: 159s
    #391763
  • Pipeline finished with Canceled
    3 months ago
    Total: 98s
    #391765
  • Pipeline finished with Success
    3 months ago
    Total: 160s
    #391767
  • Pipeline finished with Success
    3 months ago
    Total: 158s
    #391768
  • 🇩🇪Germany jurgenhaas Gottmadingen

    Ping

  • 🇩🇪Germany mxh Offenburg

    There is a "hidden" layer of how a page title can be set.

    There is an anoymous function in Drupal\Core\Render\MainContent\HtmlRenderer::prepare:

    <?php
        $get_title = function (array $main_content) use ($request, $route_match) {
          return $main_content['#title'] ?? $this->titleResolver->getTitle($request, $route_match->getRouteObject());
        };
    ?>

    It fetches the #title key from the main page content render array and uses it when set.
    For example, within Drupal\node\NodeForm::form the page title of the node edit page is being set as follows:

    <?php
        if ($this->operation == 'edit') {
          $form['#title'] = $this->t('<em>Edit @type</em> @title', [
            '@type' => node_get_type_label($node),
            '@title' => $node->label(),
          ]);
        }
    ?>

    We could make use of this mechanism, by implementing "Set Title" as a render action so that it is able to get the current render array. Then we are probably able to set the title for example on a "Build form" event.

  • 🇩🇪Germany jurgenhaas Gottmadingen

    @mxh that sounds interesting, I just wonder where we get the render array from. Does that require an extra event for when the page gets rendered?

    Would it otherwise be possible to decorate the \Drupal\Core\Block\Plugin\Block\PageTitleBlock plugin?

  • 🇩🇪Germany mxh Offenburg

    There is a listener Drupal\Core\EventSubscriber\MainContentViewSubscriber::onViewRenderArray on event Symfony\Component\HttpKernel\KernelEvents::VIEW. Within that listener method, following happens:

    // For main page content controller methods, this can (but is not forced to be) returning a renderable array.
    $result = $event->getControllerResult();
    // ...
    $renderer = $this->classResolver->getInstanceFromDefinition($this->mainContentRenderers[$wrapper]);
    // $wrapper == 'html' -> will be calling \Drupal\Core\Render\MainContent\HtmlRenderer::renderResponse
    $response = $renderer->renderResponse($result, $request, $this->routeMatch);
    // ...
    

    There is an already existing "kernel:view" event plugin in eca_misc. It could be extended to reckognize $result = $event->getControllerResult(); so in case of a renderable array, it could be instantiated as a Drupal\eca\Event\RenderEventInterface.

  • 🇩🇪Germany jurgenhaas Gottmadingen

    This sounds great, should be worth a try.

Production build 0.71.5 2024