當前位置: 首頁>>代碼示例>>PHP>>正文


PHP PluginManagerInterface::getTopicFileInfo方法代碼示例

本文整理匯總了PHP中Drupal\Component\Plugin\PluginManagerInterface::getTopicFileInfo方法的典型用法代碼示例。如果您正苦於以下問題:PHP PluginManagerInterface::getTopicFileInfo方法的具體用法?PHP PluginManagerInterface::getTopicFileInfo怎麽用?PHP PluginManagerInterface::getTopicFileInfo使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Drupal\Component\Plugin\PluginManagerInterface的用法示例。


在下文中一共展示了PluginManagerInterface::getTopicFileInfo方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: viewTopic

    /**
   * Load and render a help topic.
   *
   * @param string $module
   *   Name of the module.
   * @param string $topic
   *   Name of the topic.
   * @todo port the drupal_alter functionality.
   *
   * @return string
   *   Returns formatted topic.
   */
  public function viewTopic($module, $topic, $is_modal = false) {
    $file_info = $this->advanced_help->getTopicFileInfo($module, $topic);
    if ($file_info) {
      $info = $this->advanced_help->getTopic($module, $topic);
      $file = "{$file_info['path']}/{$file_info['file']}";
      $build = [
        '#type' => 'markup',
      ];

      if (!empty($info['css'])) {
        $build['#attached']['library'][] = $info['module'] . '/' . $info['css'];
      }

      $build['#markup'] = file_get_contents($file);
      if (isset($info['readme file']) && $info['readme file']) {
        $ext = pathinfo($file, PATHINFO_EXTENSION);
        if ('md' == $ext && $this->advanced_help->isMarkdownFilterEnabled()) {
          libraries_load('php-markdown', 'markdown-extra');
          $build['#markup'] = '<div class="advanced-help-topic">' . Xss::filterAdmin(\Michelf\MarkdownExtra::defaultTransform($build['#markup'])) . '</div>';
        }
        else {
          $readme = '';
          if ('md' == $ext) {
            $readme .=
              '<p>' .
              $this->t('If you install the !module module, the text below will be filtered by the module, producing rich text.',
                [
                  '!module' => $this->l($this->t('Markdown filter'),
                    Url::fromUri('https://www.drupal.org/project/markdown'),
                    ['attributes' => ['title' => $this->t('Link to project.')]])
                ]) . '</p>';
          }

          $readme .=
            '<div class="advanced-help-topic"><pre class="readme">' . SafeMarkup::checkPlain($build['#markup']) . '</pre></div>';
          $build['#markup'] = $readme;
        }
        return $build['#markup'];
      }

      // Change 'topic:' to the URL for another help topic.
      preg_match('/&topic:([^"]+)&/', $build['#markup'], $matches);
      if (isset($matches[1]) && preg_match('/[\w\-]\/[\w\-]+/', $matches[1])) {
        list($umodule, $utopic) = explode('/', $matches[1]);
        $path = new Url('advanced_help.help', ['module' => $umodule, 'topic' => $utopic]);
        $build['#markup'] = preg_replace('/&topic:([^"]+)&/', $path->toString(), $build['#markup']);
      }

      global $base_path;

      // Change 'path:' to the URL to the base help directory.
      $build['#markup'] = str_replace('&path&', $base_path . $info['path'] . '/', $build['#markup']);

      // Change 'trans_path:' to the URL to the actual help directory.
      $build['#markup'] = str_replace('&trans_path&', $base_path . $file_info['path'] . '/', $build['#markup']);

      // Change 'base_url:' to the URL to the site.
      $build['#markup'] = preg_replace('/&base_url&([^"]+)"/', $base_path . '$1' . '"', $build['#markup']);

      // Run the line break filter if requested.
      if (!empty($info['line break'])) {
        // Remove the header since it adds an extra <br /> to the filter.
        $build['#markup'] = preg_replace('/^<!--[^\n]*-->\n/', '', $build['#markup']);

        $build['#markup'] = _filter_autop($build['#markup']);
      }

      if (!empty($info['navigation']) && !$is_modal) {
        $topics = $this->advanced_help->getTopics();
        $topics = $this->getTopicHierarchy($topics);
        if (!empty($topics[$module][$topic]['children'])) {
          $items = $this->getTree($topics, $topics[$module][$topic]['children']);
          $links = [
            '#theme' => 'item_list',
            '#items' => $items
          ];
          $build['#markup'] .= \Drupal::service('renderer')->render($links, FALSE);
        }

        list($parent_module, $parent_topic) = $topics[$module][$topic]['_parent'];
        if ($parent_topic) {
          $parent = $topics[$module][$topic]['_parent'];
          $up = new Url('advanced_help.help', ['module' => $parent[0], 'topic' => $parent[1]]);
        }
        else {
          $up = new Url('advanced_help.module_index', ['module' => $module]);
        }

//.........這裏部分代碼省略.........
開發者ID:eloiv,項目名稱:botafoc.cat,代碼行數:101,代碼來源:AdvancedHelpController.php


注:本文中的Drupal\Component\Plugin\PluginManagerInterface::getTopicFileInfo方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。