Commit c0b35ed8 authored by Srishti Bankar's avatar Srishti Bankar Committed by Tim Plunkett
Browse files

Issue #3292996 by srishtiiee, bnjmnm, fjgarlin, aarti zikre, tim.plunkett,...

Issue #3292996 by srishtiiee, bnjmnm, fjgarlin, aarti zikre, tim.plunkett, narendraR, bnjmmn: Create a skeleton for the individual module page
parent b4bc674c
Loading
Loading
Loading
Loading
+3 −0
Changes for images/compatible-icon.svg: 3 added lines, 0 removed lines.
Original line number Diff line number Diff line
<svg width="25" height="25" fill="none" xmlns="http://www.w3.org/2000/svg">
  <path fill-rule="evenodd" clip-rule="evenodd" d="M12.5 25C19.404 25 25 19.404 25 12.5S19.404 0 12.5 0 0 5.596 0 12.5 5.596 25 12.5 25Zm-.62-7.693 6.944-8.333-1.537-1.28-6.243 7.491-3.392-3.392-1.415 1.414 4.167 4.167.774.774.701-.841Z" fill="#26A769"/>
</svg>

images/slide-icon.svg

0 → 100644
+3 −0
Changes for images/slide-icon.svg: 3 added lines, 0 removed lines.
Original line number Diff line number Diff line
<svg width="18" height="62" viewBox="0 0 18 62" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M16 1.5L1.5 30.5L16 60.5" stroke="#75767B" stroke-width="3" stroke-linejoin="round"/>
</svg>
+56 −4
Changes for modules/project_browser_devel/src/Plugin/ProjectBrowserSource/RandomDataPlugin.php: 56 added lines, 4 removed lines.
Original line number Diff line number Diff line
@@ -3,6 +3,7 @@
namespace Drupal\project_browser_devel\Plugin\ProjectBrowserSource;

use Drupal\Component\Utility\Random;
use Drupal\Core\Cache\CacheBackendInterface;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\project_browser\Plugin\ProjectBrowserSourceBase;
use Drupal\project_browser\ProjectBrowser\Project;
@@ -30,6 +31,13 @@ class RandomDataPlugin extends ProjectBrowserSourceBase implements ContainerFact
   */
  protected $randomGenerator;

  /**
   * ProjectBrowser cache bin.
   *
   * @var \Drupal\Core\Cache\CacheBackendInterface
   */
  protected $cacheBin;

  /**
   * Constructs a MockDrupalDotOrg object.
   *
@@ -39,10 +47,13 @@ class RandomDataPlugin extends ProjectBrowserSourceBase implements ContainerFact
   *   The plugin ID for the plugin instance.
   * @param mixed $plugin_definition
   *   The plugin implementation definition.
   * @param \Drupal\Core\Cache\CacheBackendInterface $cache_bin
   *   The cache bin.
   */
  public function __construct(array $configuration, $plugin_id, $plugin_definition) {
  public function __construct(array $configuration, $plugin_id, $plugin_definition, CacheBackendInterface $cache_bin) {
    parent::__construct($configuration, $plugin_id, $plugin_definition);
    $this->randomGenerator = new Random();
    $this->cacheBin = $cache_bin;
  }

  /**
@@ -52,7 +63,8 @@ class RandomDataPlugin extends ProjectBrowserSourceBase implements ContainerFact
    return new static(
      $configuration,
      $plugin_id,
      $plugin_definition
      $plugin_definition,
      $container->get('cache.project_browser'),
    );
  }

@@ -126,6 +138,26 @@ class RandomDataPlugin extends ProjectBrowserSourceBase implements ContainerFact
   * {@inheritdoc}
   */
  public function getProjects(array $query = []) : ProjectsResultsPage {
    $projects = $this->getProjectData();

    if (!empty($query['machine_name'])) {
      $projects = array_filter($projects, function ($project) use ($query) {
        return $project->field_project_machine_name === $query['machine_name'];
      });
    }

    return new ProjectsResultsPage(count($projects), $projects);
  }

  /**
   * Gets the project data from cache if available, or builds it if not.
   */
  private function getProjectData(): array {
    $stored_projects = $this->cacheBin->get('RandomData:projects');
    if ($stored_projects) {
      return $stored_projects->data;
    }

    $projects = [];
    $number_of_projects = rand(12, 36);
    $categories = $this->getCategories();
@@ -149,6 +181,7 @@ class RandomDataPlugin extends ProjectBrowserSourceBase implements ContainerFact
        'nid' => uniqid(),
        'body' => [
          'summary' => $this->randomGenerator->paragraphs(1),
          'value' => $this->randomGenerator->paragraphs(5),
        ],
        'field_project_images' => [
          [
@@ -169,13 +202,32 @@ class RandomDataPlugin extends ProjectBrowserSourceBase implements ContainerFact
        'project_usage_total' => rand(0, 100000),
        'flag_project_star_user_count' => rand(0, 100),
      ];

      // The first project will have a single image, the rest will have 3.
      if ($i !== 0) {
        $project['field_project_images'][] = [
          'file' => [
            'uri' => str_replace(4, 5, $good_image),
            'resource' => 'image',
          ],
          'alt' => $machine_name . ' something',
        ];
        $project['field_project_images'][] = [
          'file' => [
            'uri' => str_replace(4, 6, $good_image),
            'resource' => 'image',
          ],
          'alt' => $machine_name . ' another thing',
        ];
      }

      $project['is_covered'] = $this->projectIsCovered($project);
      $project['is_active'] = $this->projectIsActive($project);
      $project['is_maintained'] = $this->projectIsMaintained($project);
      $projects[] = new Project($project);
    }

    return new ProjectsResultsPage(count($projects), $projects);
    $this->cacheBin->set('RandomData:projects', $projects);
    return $projects;
  }

  /**
+25 −0
Changes for project_browser.install: 25 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -97,6 +97,13 @@ function project_browser_schema() {
          'not null' => FALSE,
          'size' => 'big',
        ],
        'field_project_machine_name' => [
          'description' => 'Project machine name',
          'type' => 'varchar',
          'length' => 255,
          'not null' => TRUE,
          'default' => '',
        ],
      ],
      'primary key' => ['nid'],
    ],
@@ -147,6 +154,7 @@ function _project_browser_populate_from_fixture() {
      'flag_project_star_user_count',
      'field_project_type',
      'project_data',
      'field_project_machine_name',
    ]);
    foreach ($chunk_projects as $project) {
      if ($project['changed'] > $most_recent_change) {
@@ -156,6 +164,7 @@ function _project_browser_populate_from_fixture() {
      $project_data = unserialize($project['project_data']);
      $project['maintenance_status'] = $project_data['taxonomy_vocabulary_44']['id'];
      $project['development_status'] = $project_data['taxonomy_vocabulary_46']['id'];
      $project['field_project_machine_name'] = $project_data['field_project_machine_name'];

      $query->values($project);
    }
@@ -225,3 +234,19 @@ function project_browser_update_9005() {
  $connection->truncate('project_browser_categories')->execute();
  _project_browser_populate_from_fixture();
}

function project_browser_update_9006() {
  $spec = [
    'description' => 'Project machine name',
    'type' => 'varchar',
    'length' => 255,
    'not null' => TRUE,
    'default' => '',
  ];
  $connection = Database::getConnection();
  $schema = $connection->schema();
  $schema->addField('project_browser_projects', 'field_project_machine_name', $spec);
  $connection->truncate('project_browser_projects')->execute();
  $connection->truncate('project_browser_categories')->execute();
  _project_browser_populate_from_fixture();
}
+2 −1
Changes for project_browser.routing.yml: 2 added lines, 1 removed line.
Original line number Diff line number Diff line
@@ -49,9 +49,10 @@ project_browser.api_project_get_all:
  #options:
  #  no_cache: 'TRUE'
project_browser.browse:
  path: '/admin/modules/browse'
  path: '/admin/modules/browse/{module_name}'
  defaults:
    _controller: '\Drupal\project_browser\Controller\BrowserController::browse'
    _title: 'Browse Drupal.org projects'
    module_name: ''
  requirements:
    _permission: 'administer modules'
Loading