Commit bdad7399 authored by Nitin Lama's avatar Nitin Lama 🤠 Committed by jyoti
Browse files

Issue #2997688 by AstonVictor, nitin_lama, Abhijith S, nehajyoti, Arturo1007: Coding standard

parent 98d2d2eb
Loading
Loading
Loading
Loading
+10 −4
Changes for src/TaxonomyMenuTrailsBreadcrumbBuilder.php: 10 added lines, 4 removed lines.
Original line number Diff line number Diff line
@@ -96,7 +96,8 @@ class TaxonomyMenuTrailsBreadcrumbBuilder implements BreadcrumbBuilderInterface
      $entity_type = 'node';
      $type = $this->entityTypeManager->getStorage('node_type')
        ->load($bundle);
      // Check if node type is selected in content type taxonomy trails settings.
      // Check if node type is selected in
      // content type taxonomy trails settings.
      // Check all the settings from content type configuration form.
      $configurations = $type->getThirdPartySetting('taxonomy_menu_trails', 'taxonomy_menu_trails', []);
      if (empty($configurations)) {
@@ -106,12 +107,14 @@ class TaxonomyMenuTrailsBreadcrumbBuilder implements BreadcrumbBuilderInterface
      switch ($configurations['set_breadcrumb']) {
        case "never":
          return FALSE;

        case 'if_empty':
          $trailIds = $this->menuActiveTrail->getActiveTrailIds('main');
          if (!$trailIds) {
            return FALSE;
          }
          break;

        case 'always':
          break;
      }
@@ -119,10 +122,12 @@ class TaxonomyMenuTrailsBreadcrumbBuilder implements BreadcrumbBuilderInterface
      $field_definitions = $this->entityFieldManager
        ->getFieldDefinitions($entity_type, $bundle);
      foreach ($field_definitions as $field_name => $field_definition) {
        // Look for a "taxonomy attachment" by node field, regardless of language.
        // Look for a "taxonomy attachment" by node field,
        // regardless of language.
        if ($configurations['taxonomy_term_references'][$field_name] ?? NULL) {
          if (!empty($field_definition->getTargetBundle())) {
            // Check for term_reference/entity_reference fields from the content type.
            // Check for term_reference/entity_reference fields
            // from the content type.
            if ($field_definition->getType() == 'entity_reference') {
              // Check all taxonomy terms applying to the current page.
              foreach ($node_object->getFields() as $field) {
@@ -153,7 +158,8 @@ class TaxonomyMenuTrailsBreadcrumbBuilder implements BreadcrumbBuilderInterface
      foreach ($node_object->getFields() as $field) {
        if ($field->getSetting('target_type') == 'taxonomy_term') {
          foreach ($field->referencedEntities() as $term) {
            $url = $term->toUrl();$route_links = $this->menuLinkManager->loadLinksByRoute($url->getRouteName(), $url->getRouteParameters());
            $url = $term->toUrl();
            $route_links = $this->menuLinkManager->loadLinksByRoute($url->getRouteName(), $url->getRouteParameters());
            if (!empty($route_links)) {
              $taxonomy_term_link = reset($route_links);
              $plugin_definition = $taxonomy_term_link->getPluginDefinition();
+1 −3
Changes for taxonomy_menu_trails.install: 1 added line, 3 removed lines.
Original line number Diff line number Diff line
@@ -6,10 +6,8 @@
 */

/**
 * Implements hook_uninstall()
 * Implements hook_uninstall().
 */
function taxonomy_menu_trails_uninstall() {
  \Drupal::configFactory()->getEditable('taxonomy_menu_trails.settings')->delete();
}

+51 −48
Changes for taxonomy_menu_trails.module: 51 added lines, 48 removed lines.
Original line number Diff line number Diff line
@@ -22,10 +22,13 @@ function taxonomy_menu_trails_form_alter(&$form, FormStateInterface &$form_state
 * Add Taxonomy Menu Trails settings to bundle form.
 *
 * @param array $form
 *   Form Array.
 * @param string $entity_type
 *   String Entity Type.
 * @param mixed $bundle
 *   Mixed bundle.
 */
function _taxonomy_menu_trails_alter_bundle_form(&$form, $entity_type, $bundle, $form_state) {
function _taxonomy_menu_trails_alter_bundle_form(array &$form, $entity_type, $bundle, $form_state) {
  /** @var \Drupal\Core\Entity\EntityFieldManagerInterface $entity_field_manager */
  $entity_field_manager = \Drupal::service('entity_field.manager');

@@ -48,119 +51,119 @@ function _taxonomy_menu_trails_alter_bundle_form(&$form, $entity_type, $bundle,
      $default_paths = t('paths "node/[nid]" and "node/[nid]/*"');
      break;

    // TODO: Support for other entity types.
    // @todo Support for other entity types.
  }
  if (!empty($bundleFields)) {

    // Build term path options.
    $term_path_options = array(
    $term_path_options = [
      'default' => t('Default'),
      'custom' => t('Custom patterns'),
      'api' => t('Ask modules using API'),
    );
    ];
    if (\Drupal::moduleHandler()->moduleExists('taxonomy_menu')) {
      $term_path_options += array(
      $term_path_options += [
        'tm' => t('Ask Taxonomy Menu'),
      );
      ];
    }

    $type = $form_state->getFormObject()->getEntity();
    $default_value = $type->getThirdPartySetting('taxonomy_menu_trails', 'taxonomy_menu_trails', []);

    $subform = array(
    $subform = [
      '#tmt_entity' => $entity_type,
      '#tmt_bundle' => $bundle,
      'taxonomy_term_references' => array(
      'taxonomy_term_references' => [
        '#type' => 'checkboxes',
        '#title' => t('Term references for setting active trail'),
        '#options' => $bundleFields,
        '#default_value' => $default_value['taxonomy_term_references'] ?? [],
      ),
      'selection_method' => array(
        // TODO convert it to 'value' if there is one term reference with
        // Number of values == 1
      ],
      'selection_method' => [
        // @todo convert it to 'value' if there is one term reference with
        // Number of values == 1.
        '#type' => 'select',
        '#title' => t("Term selection method"),
        '#description' => t("This option defines how module chooses term for processing:<ul><li><b>First/Last</b> - select first/last term with menu item.</li><li><b>Deepest in menu</b> - use term with deepest menu item.</ul>"),
        '#default_value' => $default_value['selection_method'] ?? NULL,
        '#options' => array(
        '#options' => [
          'first' => t('First term'),
          'last' => t('Last term'),
          'deepest-in-menu' => t('Deepest in menu'),
        ),
      ),
      'terms_with_current_language' => \Drupal::moduleHandler()->moduleExists('i18n_taxonomy') ? array(
        ],
      ],
      'terms_with_current_language' => \Drupal::moduleHandler()->moduleExists('i18n_taxonomy') ? [
        '#type' => 'checkbox',
        '#title' => t("Allow only terms with the current language"),
        '#description' => t("This option will check the taxonomy term language and allow only those terms that are localized into current content language."),
        '#default_value' => $default_value['terms_with_current_language'] ?? NULL,
      ) : array(),
      'only_without_menu' => array(
      ] : [],
      'only_without_menu' => [
        '#type' => 'checkbox',
        '#title' => t("Only if @entity doesn't have enabled menu item", array('@entity' => mb_strtolower($bundle_label))),
        '#title' => t("Only if @entity doesn't have enabled menu item", ['@entity' => mb_strtolower($bundle_label)]),
        '#description' => t("This option also applies to pages detected with path pattern. You should think twice before turning this option on, because it'll reduce site performance a bit."),
        '#default_value' => $default_value['only_without_menu'] ?? NULL,
      ),
      'trail_per_menu' => array(
      ],
      'trail_per_menu' => [
        '#type' => 'checkbox',
        '#title' => t("Separate active trail for each menu"),
        '#description' => t("Makes it possible to expand multiple menus. Otherwise only one trail in the most preferred menu will be active."),
        '#default_value' => $default_value['trail_per_menu'] ?? NULL,
      ),
      'set_breadcrumb' => array(
      ],
      'set_breadcrumb' => [
        '#type' => 'select',
        '#title' => t('Add active trail to the breadcrumb'),
        '#description' => t('Menu items from active trail will be inserted to the beginning of default breadcrumb when this option is enabled and the term was chosen.'),
        '#options' => array(
        '#options' => [
          'never' => t('Never'),
          'if_empty' => t('When breadcrumb is empty'),
          'always' => t('Always'),
        ),
        ],
        '#default_value' => $default_value['set_breadcrumb'] ?? NULL,
      ),
      'term_path' => array(
      ],
      'term_path' => [
        '#type' => 'select',
        '#title' => t('Term path'),
        '#options' => $term_path_options,
        '#default_value' => $default_value['term_path'] ?? NULL,
      ),
      'term_path_patterns' => array(
      ],
      'term_path_patterns' => [
        '#type' => 'textarea',
        '#title' => t('Term path patterns'),
        '#description' => t("Enter one pattern per line. Only [tid] placeholder is available. For complex path patterns use API instead. Default pattern taxonomy/term/[tid] is not included by default."),
        '#default_value' => implode("\n", $default_value['term_path_patterns'] ?? []),
        '#states' => array(
          'visible' => array(
            'select[name="taxonomy_menu_trails[term_path]"]' => array('value' => 'custom'),
          ),
        ),
      ),
      'paths_ui' => array(
        '#title' => t('Additional path patterns for @entity detection', array('@entity' => mb_strtolower($bundle_label))),
        '#states' => [
          'visible' => [
            'select[name="taxonomy_menu_trails[term_path]"]' => ['value' => 'custom'],
          ],
        ],
      ],
      'paths_ui' => [
        '#title' => t('Additional path patterns for @entity detection', ['@entity' => mb_strtolower($bundle_label)]),
        '#type' => 'textarea',
        '#description' => t('Enter one pattern per line. By default, module is trying to detect @entity at @default_paths. Here you can specify additional paths to detect @entity and set menu trails for it. The "*" character matches any non-empty string, the "%" character matches non-empty string without "/" character. Available placeholders are:<ul><li>[@id] - @entity ID</li><li>[@title] - @entity title</li></ul>Each additional pattern will be tested on each page load, so use it only if you really need this feature.', array(
        '#description' => t('Enter one pattern per line. By default, module is trying to detect @entity at @default_paths. Here you can specify additional paths to detect @entity and set menu trails for it. The "*" character matches any non-empty string, the "%" character matches non-empty string without "/" character. Available placeholders are:<ul><li>[@id] - @entity ID</li><li>[@title] - @entity title</li></ul>Each additional pattern will be tested on each page load, so use it only if you really need this feature.', [
          '@entity' => mb_strtolower($bundle_label),
          '@default_paths' => $default_paths,
          '@id' => 'node',
          '@title' => 'title',
        )),
      ),
    );
        ]),
      ],
    ];
    array_unshift($form['#submit'], 'taxonomy_menu_trails_bundle_form_submit');
  }
  else {
    $subform = array(
      'notice' => array(
        '#markup' => '<p>' . t('Add some "Term reference" fields to use Taxonomy Menu Trails.') . '</p>'
      ),
    );
    $subform = [
      'notice' => [
        '#markup' => '<p>' . t('Add some "Term reference" fields to use Taxonomy Menu Trails.') . '</p>',
      ],
    ];
  }

  $form['taxonomy_menu_trails'] = array(
  $form['taxonomy_menu_trails'] = [
    '#tree' => TRUE,
    '#type' => 'details',
    '#title' => t('Taxonomy menu trails'),
    ) + $subform;
  ] + $subform;

  $form['#entity_builders'][] = 'taxonomy_menu_trails_form_node_type_form_builder';
}
+1 −1

File changed.

Contains only whitespace changes.