devdocs-8.x-1.x-dev/devdocs.module

devdocs.module
<?php


/**
 * @file
 * Contains devdocs.module..
 */

use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\devdocs\StreamWrapper\DocsStream;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Datetime\DateFormatterInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Form\ConfigFormBase;
use Drupal\Core\StreamWrapper\StreamWrapperInterface;
use Drupal\Core\StreamWrapper\StreamWrapperManagerInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Drupal\node\Entity\NodeType;

use Drupal\views\Views;
use Drupal\Component\Utility\SafeMarkup;
use Drupal\filter\FilterProcessResult;
use Drupal\Component\Utility\Xss;

/**
 * Implements hook_help().
 */
function devdocs_help($route_name, RouteMatchInterface $route_match) {
  switch ($route_name) {
    // Main module help for the devdocs module.
    case 'help.page.devdocs':
      $output = '';
      $output .= '<h3>' . t('About') . '</h3>';
      $output .= '<p>' . t('Description') . '</p>';
      return $output;

    default:
  }
}


/**
 * Implements hook_form_FORM_ID_alter().
 */
function devdocs_form_system_file_system_settings_alter(&$form, $form_state, $form_id) {

  $form['file_docs_path'] = array(
    '#type' => 'item',
    '#title' => t('Developer Documentation directory path'),
    '#markup' => (DocsStream::basePath() ? DocsStream::basePath() : t('Not set')),
    '#description' => t('An existing local file system path for storing Developer Documentation files. It should be writable by Drupal and not accessible over the web. See the online handbook for <a href="@handbook">more information about securing private files</a>.', array('@handbook' => 'http://drupal.org/documentation/modules/file')),
  );

  // rearrange form
  // if (isset($form['actions'])) {
  //   $form['actions']['#weight'] = 50;
  // }
  // if (isset($form['file_default_scheme'])) {
  //   $form['file_default_scheme']['#weight'] = 10;
  // }
}



function devdocs_recreate() {

  file_unmanaged_copy(drupal_get_path('module', 'devdocs') . '/template/index.html', 'docs://index.html', FILE_EXISTS_ERROR);

  $template_docs = array('development', 'hacks', 'index', 'modules', 'navigation', 'theme');
  foreach ($template_docs as $doc) {
    file_unmanaged_copy(drupal_get_path('module', 'devdocs') . '/template/'.$doc.'.md', 'docs://'.$doc.'.md', FILE_EXISTS_ERROR);
  }

  $autogen_docs = array('content_types', 'features', 'views');
  foreach ($autogen_docs as $doc) {
    $uri = 'docs://' . $doc . '.md';
    $markdown = call_user_func('devdocs_'.$doc.'_info_output');
    file_unmanaged_save_data($markdown, $uri, FILE_EXISTS_ERROR);
  }
}


function devdocs_views_info_output() {
  $lines[] = 'Views';
  $lines[] = '=============';
  $lines[] = '';
  $lines[] = 'The following views are used in this project.';
  $views = Views::getAllViews();
  ksort($views);
  foreach ($views as $name => $view) {
    if ($view->status()) {
      $lines[] = '## ' . $view->get('label');
      $lines[] = '['. $view->get('id') . ']';
      $lines[] = $view->get('description');
      $lines[] = '';
      $lines[] = 'Display  |Name  |Display plugin   ';
      $lines[] = '---------|------|-----------------';
      foreach ($view->get('display') as $id => $display) {
        $enabled = !empty($display['display_options']['enabled']) || !array_key_exists('enabled', $display['display_options']);
        if ($enabled) {
          $lines[] = $display['display_title'] . '|' . $display['id'] . '|' . $display['display_plugin'];
        }
      }
      $lines[] = '';
    }
  }
  $output = implode(PHP_EOL, $lines);
  return Xss::filter($output);
}

// function devdocs_features_info_output() {
//   $lines[] = 'Features';
//   $lines[] = '=============';
//   $lines[] = '';
//   $lines[] = 'The following features are used in this project.';
//   $features = features_get_features();
//   ksort($features);
//   foreach ($features as $name => $feature) {
//     if ($feature->status == '1') {
//       $lines[] = '## ' . $feature->info['name'];
//       $lines[] = '['. $name . ']';
//       $lines[] = '';
//       $lines[] = '* ' . $feature->info['description'];
//       $lines[] = '* ' . $feature->info['package'];
//       $lines[] = '';
//     }
//   }
//   $output = implode(PHP_EOL, $lines);
//   return check_plain($output);
// }


function devdocs_content_types_info_output() {
  $lines[] = 'Content Types';
  $lines[] = '=============';
  $lines[] = '';
  $lines[] = 'The following content types (nodes) are used in this project.';
  $types = NodeType::loadMultiple();
  ksort($types);
  foreach ($types as $name => $type) {
    $lines[] = '## ' . $type->get('name');
    $lines[] = '';
    $lines[] = '* Type: ' . $type->get('type');
    $lines[] = '* Module: ' . $type->get('module');
    $lines[] = '';
    if (!empty($type->get('description'))) {
      $lines[] = $type->get('description');
    }
    else {
      $lines[] = '[Add Description](/admin/structure/types/manage/'.$type->get('type').')';
    }

    $lines[] = 'Field Label  |Name  |Type   |Translatable  ';
    $lines[] = '-------------|------|-------|--------------';
    $fields_info = \Drupal::entityManager()->getFieldDefinitions('node', $type->get('type'));
    // dpm($fields_info);
    foreach ($fields_info as $field_name => $field_definition) {
      $lines[] = $field_definition->getLabel(). '|' . 'field_name' . '|' . $field_definition->getType(). '|';
    }

    $lines[] = '';
    $lines[] = '-------------------------------------------------------------------------------';
    $lines[] = '';
  }
  $output = implode(PHP_EOL, $lines);
  return Xss::filter($output);
}

Главная | Обратная связь

drupal hosting | друпал хостинг | it patrol .inc