Problem/Motivation

If we look at the contents of radiostoslider.module file:

/**
 * Implements hook_help().
 */
// @phpstan-ignore-next-line
#[LegacyHook]
// phpcs:ignore
function radiostoslider_help($route_name, RouteMatchInterface $route_match) {
  switch ($route_name) {
    case 'help.page.radiostoslider':
      $output = '<p> ' . t(
        '@radiostoslider is a module that allows the content managers to use the
        @lib plugin for the List radios entity field types. <br/>
        The module also provides a WebForm element that uses the Radio to Slider
        plugin. <br />
        No additional module\'s configuration required.<br />
        <h3>How to install:</h3><br />
        <ol>
        <li>Install the module.</li>
        <li>Install the Radios to Slider library: Download it and save it to
        your "/libraries/radios-to-slider" folder.</li>
        </ol>
        <h3>How to use:</h3><br />
        Go to Edit the Entity display form and select the Radios to Slider
        widget for the select list fields, configure it.',
        [
          '@radiostoslider' => Link::fromTextAndUrl(
            t('Radios to Slider'),
            Url::fromUri('https://www.drupal.org/project/radiostoslider')
          )->toString(),
          '@lib' => Link::fromTextAndUrl(
            t('Radios to Slider'),
            Url::fromUri('https://github.com/rubentd/radios-to-slider')
          )->toString(),
        ]
      ) . '</p>';

      return $output;
  }
}

/**
 * Implements hook_page_attachments().
 */
// @phpstan-ignore-next-line
#[LegacyHook]
// phpcs:ignore
function radios_to_slider_page_attachments(array &$page): void {
  $page['#attached']['library'][] = 'radiostoslider/global-scripts';
}

/**
 * Implements hook_theme().
 */
// @phpstan-ignore-next-line
#[LegacyHook]
// phpcs:ignore
function radiostoslider_theme() {
  return [
    'radios_to_slider' => [
      'render element' => 'element',
    ],
  ];
}

/**
 * Prepares variables for radios-to-slider templates.
 *
 * Default template: radios-to-slider.html.twig.
 *
 * @param array $vars
 *   An associative array containing:
 *   - element: An associative array containing the properties of the element.
 *     Properties used: #title, #value, #options, #description, #required,
 *     #attributes, #children.
 */
// @phpstan-ignore-next-line
#[LegacyHook]
// phpcs:ignore
function template_preprocess_radios_to_slider(array &$vars) {
  $element = $vars['element'];
  $vars['attributes'] = [];

  if (isset($element['#id'])) {
    $vars['attributes']['id'] = $element['#id'];
  }

  if (isset($element['#attributes']['title'])) {
    $vars['attributes']['title'] = $element['#attributes']['title'];
  }

  $vars['attributes']['data-animation'] =
    !empty($element['#animation']) ? 1 : 0;
  $vars['attributes']['data-fit-container'] =
    !empty($element['#fit_container']) ? 1 : 0;
  $vars['children'] = $element['#children'];
}

This is duplicated code that is already implemented as service methods at /src/Hook/RadiosToSlider.php so these need to converted to calls to these service methods.

Steps to reproduce

N/A

Proposed resolution

Look for the info above

Remaining tasks

N/A

User interface changes

N/A

API changes

N/A

Data model changes

N/A

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

danrod created an issue. See original summary.

adwivedi008 made their first commit to this issue’s fork.

ritarshi_chakraborty made their first commit to this issue’s fork.

ritarshi_chakraborty’s picture

Status: Active » Needs review

Please review my MR.

danrod’s picture

I tested this on my local D10.5.6 environment and I got this error:

The website encountered an unexpected error. Try again later.

Error: Class "Drupal\radiostoslider\Hook\RadiosToSliderHooks" not found in Drupal\Component\DependencyInjection\Container->createService() (line 261 of core/lib/Drupal/Component/DependencyInjection/Container.php).
Drupal\Component\DependencyInjection\Container->get() (Line: 197)
Drupal::service() (Line: 38)
radiostoslider_theme() (Line: 507)
Drupal\Core\Theme\Registry->processExtension() (Line: 400)
Drupal\Core\Theme\Registry->Drupal\Core\Theme\{closure}() (Line: 395)
Drupal\Core\Extension\ModuleHandler->invokeAllWith() (Line: 399)
Drupal\Core\Theme\Registry->build() (Line: 281)
Drupal\Core\Theme\Registry->get() (Line: 88)
Drupal\Core\Utility\ThemeRegistry->initializeRegistry() (Line: 69)
Drupal\Core\Utility\ThemeRegistry->__construct() (Line: 319)
Drupal\Core\Theme\Registry->getRuntime() (Line: 141)
Drupal\Core\Theme\ThemeManager->render() (Line: 490)
Drupal\Core\Render\Renderer->doRender() (Line: 248)
Drupal\Core\Render\Renderer->render() (Line: 1796)
Drupal\views\Plugin\views\field\FieldPluginBase->theme() (Line: 769)
Drupal\views\Plugin\views\style\StylePluginBase->elementPreRenderRow()
call_user_func_array() (Line: 113)
Drupal\Core\Render\Renderer->doTrustedCallback() (Line: 886)
Drupal\Core\Render\Renderer->doCallback() (Line: 431)
Drupal\Core\Render\Renderer->doRender() (Line: 248)
Drupal\Core\Render\Renderer->render() (Line: 708)
Drupal\views\Plugin\views\style\StylePluginBase->renderFields() (Line: 574)
Drupal\views\Plugin\views\style\StylePluginBase->renderGrouping() (Line: 462)
Drupal\views\Plugin\views\style\StylePluginBase->render() (Line: 2177)
Drupal\views\Plugin\views\display\DisplayPluginBase->render() (Line: 1593)
Drupal\views\ViewExecutable->render() (Line: 201)
Drupal\views\Plugin\views\display\Page->execute() (Line: 1690)
Drupal\views\ViewExecutable->executeDisplay() (Line: 81)
Drupal\views\Element\View::preRenderViewElement()
call_user_func_array() (Line: 113)
Drupal\Core\Render\Renderer->doTrustedCallback() (Line: 886)
Drupal\Core\Render\Renderer->doCallback() (Line: 431)
Drupal\Core\Render\Renderer->doRender() (Line: 248)
Drupal\Core\Render\Renderer->render() (Line: 238)
Drupal\Core\Render\MainContent\HtmlRenderer->Drupal\Core\Render\MainContent\{closure}() (Line: 637)
Drupal\Core\Render\Renderer->executeInRenderContext() (Line: 231)
Drupal\Core\Render\MainContent\HtmlRenderer->prepare() (Line: 128)
Drupal\Core\Render\MainContent\HtmlRenderer->renderResponse() (Line: 90)
Drupal\Core\EventSubscriber\MainContentViewSubscriber->onViewRenderArray()
call_user_func() (Line: 111)
Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch() (Line: 186)
Symfony\Component\HttpKernel\HttpKernel->handleRaw() (Line: 76)
Symfony\Component\HttpKernel\HttpKernel->handle() (Line: 53)
Drupal\Core\StackMiddleware\Session->handle() (Line: 48)
Drupal\Core\StackMiddleware\KernelPreHandle->handle() (Line: 28)
Drupal\Core\StackMiddleware\ContentLength->handle() (Line: 32)
Drupal\big_pipe\StackMiddleware\ContentLength->handle() (Line: 116)
Drupal\page_cache\StackMiddleware\PageCache->pass() (Line: 90)
Drupal\page_cache\StackMiddleware\PageCache->handle() (Line: 48)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle() (Line: 51)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle() (Line: 36)
Drupal\Core\StackMiddleware\AjaxPageState->handle() (Line: 51)
Drupal\Core\StackMiddleware\StackedHttpKernel->handle() (Line: 741)
Drupal\Core\DrupalKernel->handle() (Line: 19)

This needs to be fixed.

danrod’s picture

Status: Needs review » Needs work
ritarshi_chakraborty’s picture

That is weird. My site is running well and I'm getting no such error :)

ritarshi_chakraborty’s picture

Hey @danrod, do you still see the error?

danrod’s picture

Hi @ritarshi_chakraborty , yes, I still see the error, I'll review this again later today. Thank you.

danrod’s picture

Hi @ritarshi_chakraborty , I reviewed this again and it's working on me now, thanks a lot for your work on this, I'll move this to "Fixed" and merge it to the 2.0.x branch. Thanks !

danrod’s picture

Status: Needs work » Needs review
danrod’s picture

Status: Needs review » Reviewed & tested by the community

danrod’s picture

Status: Reviewed & tested by the community » Fixed

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.

Status: Fixed » Closed (fixed)

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