Create helper service

Created on 21 October 2024, 4 months ago

Problem/Motivation

Currently we have a bit of duplicate code through in the blocks and tour.module file. Think it would be nice to create a helper service for common functionality.

Think a function to check if results are empty i.e.

    // Check if the current matching path is the front page.
    if ($this->pathMatcher->isFrontPage()) {
      $route_name = '<front>';
    }

    $results = $this->entityTypeManager->getStorage('tour')
      ->getQuery()
      ->condition('routes.*.route_name', $route_name);

    if ($route_match->getRouteObject()) {
      foreach ($route_match->getParameters() as $name => $parameter) {
        if ($parameter instanceof EntityInterface && is_numeric($parameter->id())) {
          $results->condition('routes.*.route_params.' . $name, $parameter->id());
          break;
        }
      }
    }

    $results = $results->condition('status', TRUE)
      ->accessCheck(FALSE)
      ->execute();
    $no_tips = empty($results);

something that gets avail/no available text i.e.

  $config = $this->configFactory->get('tour.settings');
    if ($config->get('display_custom_labels')) {
      $tour_avail_text = $config->get('tour_avail_text');
      $tour_no_avail_text = $config->get('tour_no_avail_text');
    }
    else {
      $tour_avail_text = $this->t('Tour');
      $tour_no_avail_text = $this->t('No tour');
    }

Think that's a good start

Steps to reproduce

Proposed resolution

1. Create helper service
2. Inject that service where needed
3. Remove un-needed services from blocks now that they would be injected into the service
4. Do replacements

Remaining tasks

Implement
Review

User interface changes

N/A

API changes

New service

Data model changes

N/A

πŸ“Œ Task
Status

Active

Version

2.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States smustgrave

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

Merge Requests

Comments & Activities

Production build 0.71.5 2024