يضيف دروبال امتدادًا داخل علامات في قوائم لطيفة

StackOverflow https://stackoverflow.com/questions/2453650

  •  20-09-2019
  •  | 
  •  

سؤال

أحاول إضافة القوائم المنسدلة إلى موضوع دروبال الذي يستخدم تقريبا CSS Door.

يستخدم الإصدار الحالي حقن روابط أساسية من المدى إلى العلامات A ، والتي تعمل بشكل جيد. ولكن لا تدعم القوائم المنسدلة.

رمز العمل:

<?php print theme('links', $primary_links, array('class' => 'links primary-links')) ?>

في القالب مع إضافة ملف template.php:

<?php
// function for injecting spans inside anchors which we need for the theme's rounded corner background images
function strands_guybrush_links($links, $attributes =  array('class' => 'links')) {
  $output = '';
  if (count($links) > 0) {
    $output = '<ul'. drupal_attributes($attributes) .'>';

    $num_links = count($links);
    $i = 1;

    foreach ($links as $key => $link) {
      $class = $key;

      // Add first, last and active classes to the list of links to help out themers.
      if ($i == 1) {
        $class .= ' first';
      }
      if ($i == $num_links) {
        $class .= ' last';
      }
      if (isset($link['href']) && ($link['href'] == $_GET['q'] || ($link['href'] == '<front>' && drupal_is_front_page()))) {
        $class .= ' active';
      }
      $output .= '<li'. drupal_attributes(array('class' => $class)) .'>';

      if (isset($link['href'])) {
        $link['title'] = '<span class="link">' . check_plain($link['title']) . '</span>';
        $link['html'] = TRUE;      
        // Pass in $link as $options, they share the same keys.
        $output .= l($link['title'], $link['href'], $link);        
      }
      else if (!empty($link['title'])) {
        // Some links are actually not links, but we wrap these in <span> for adding title and class attributes
        if (empty($link['html'])) {
          $link['title'] = check_plain($link['title']);
        }
        $span_attributes = '';
        if (isset($link['attributes'])) {
          $span_attributes = drupal_attributes($link['attributes']);
        }
        $output .= '<span'. $span_attributes .'>'. $link['title'] .'</span>';
      }

      $i++;
      $output .= "</li>\n";
    }

    $output .= '</ul>';
  }
  return $output;
}
?>

لذلك أضفت وحدة قائمة لطيفة الذي يعمل بشكل جيد ويسمح بوظائف القائمة المنسدلة للتنقل الخاص بي والتي يتم تناولها الآن من القالب باستخدام:

<?php   print theme_nice_menu_primary_links() ?>

تكمن المشكلة في أن العلامات A تحتاج إلى أن يكون للداخل للسماح بتوصيف الحالة المحددة. لقد جربت كل زاوية يمكنني العثور عليها لتحرير Drupal Function Menu_item_Link والتي تستخدمها قوائم لطيفة لبناء الروابط.

على سبيل المثال ، نظرت إلى منتدى دروبال لمدة يومين ولا فرح.

الخطوط الموجودة في الوحدة النمطية التي تبني الروابط هي:

function theme_nice_menu_build($menu) {
  $output = '';
  // Find the active trail and pull out the menus ids.

  menu_set_active_menu_name('primary-links');
  $trail = menu_get_active_trail('primary-links');
  foreach ($trail as $item) {
    $trail_ids[] = $item['mlid'];
  }

  foreach ($menu as $menu_item) {
    $mlid = $menu_item['link']['mlid'];
    // Check to see if it is a visible menu item.
    if ($menu_item['link']['hidden'] == 0) {
      // Build class name based on menu path
      // e.g. to give each menu item individual style.
      // Strip funny symbols.
      $clean_path = str_replace(array('http://', '<', '>', '&', '=', '?', ':'), '', $menu_item['link']['href']);
      // Convert slashes to dashes.
      $clean_path = str_replace('/', '-', $clean_path);
      $class = 'menu-path-'. $clean_path;
      $class .= in_array($mlid, $trail_ids) ? ' active' : '';  
      // If it has children build a nice little tree under it.
      if ((!empty($menu_item['link']['has_children'])) && (!empty($menu_item['below']))) {
        // Keep passing children into the function 'til we get them all.
        $children = theme('nice_menu_build', $menu_item['below']);
        // Set the class to parent only of children are displayed.
        $class .= $children ? ' menuparent ' : '';
        // Add an expanded class for items in the menu trail.
        $output .= '<li id="menu-'. $mlid .'" class="'. $class .'">'. theme('menu_item_link', $menu_item['link']);
        // Build the child UL only if children are displayed for the user.
        if ($children) {
          $output .= '<ul>';
          $output .= $children;
          $output .= "</ul>\n";
        }  
        $output .= "</li>\n";
      }  
      else {
        $output .= '<li id="menu-'. $mlid .'" class="'. $class .'">'. theme('menu_item_link', $menu_item['link']) .'</li>'."\n";
      }  
    }  
  }
  return $output;
}

كما يمكنك رؤية $ outputing يستخدم menu_item_link لتحليل الصفيف في الروابط ولإضافة فئة النشطة إلى رابط التنقل المحدد.

والسؤال هو كيف يمكنني إضافة فترة داخل العلامات A أو كيف يمكنني لف العلامات A مع فترة تحتوي على الفئة النشطة لتصميم روابط الأبواب المنزلق؟

هل كانت مفيدة؟

المحلول

إذا كنت ترغب في لف العلامات A مع فترة ، يمكنك الكتابة فوق theme_nice_menu_build وأضف فترةك إلى الإخراج. إذا كنت تريد داخل العلامة ، فأنت بحاجة إلى الكتابة فوق menu_item_link.

يمكنك الكتابة فوق موضوع funciton عن طريق إنشاء استدعاء وظيفة your_theme_name_function_name وسوف تستخدم Drupal هذه الوظيفة لتقديم الترميز بدلاً من الوضع الافتراضي. بهذه الطريقة يمكنك تغيير الترميز بأي طريقة تريدها. يجب أن تكون هذه الوظيفة في ملف template.php الخاص بك.

هناك طريقة جيدة للبدء وهي نسخ الوظيفة التي تريد الكتابة فوقها وتغييرها إلى رغبتك.

لقد حدث الكثير منذ دروبال 4.7 ، لا آمل أن تستخدم ذلك. من السهل جدًا إدراج علامات Spans:

function your_theme_name_menu_item_link($link) {
  if (empty($link['localized_options'])) {
    $link['localized_options'] = array();
  }
  $link['localized_options']['html'] = TRUE;
  return l('<span>' . $link['title'] . '</span>', $link['href'], $link['localized_options']);
}

لقد اختبرت هذا وهو يعمل بشكل جيد.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top