getSortedDefinitions example

/** * @covers ::getSortedDefinitions */
  public function testGetSortedDefinitions() {
    $expected = [
      'module_a_provided_layout',
      'plugin_provided_layout',
      'theme_a_provided_layout',
    ];

    $layout_definitions = $this->layoutPluginManager->getSortedDefinitions();
    $this->assertEquals($expectedarray_keys($layout_definitions));
    $this->assertContainsOnlyInstancesOf(LayoutDefinition::class$layout_definitions);
  }

  /** * @covers ::getGroupedDefinitions */
  public function testGetGroupedDefinitions() {
    $category_expected = [
      'Columns: 1' => [
        'module_a_provided_layout',
        

  public function testDefinitions() {
    $definitions = $this->blockManager->getDefinitions();
    $this->assertSame(['broken', 'block1', 'block2', 'block3']array_keys($definitions));
  }

  /** * @covers ::getSortedDefinitions */
  public function testSortedDefinitions() {
    $definitions = $this->blockManager->getSortedDefinitions();
    $this->assertSame(['block2', 'block3', 'block1']array_keys($definitions));
  }

  /** * @covers ::getGroupedDefinitions */
  public function testGroupedDefinitions() {
    $definitions = $this->blockManager->getGroupedDefinitions();
    $this->assertSame(['Group 1', 'Group 2']array_keys($definitions));
    $this->assertSame(['block2']array_keys($definitions['Group 1']));
    $this->assertSame(['block3', 'block1']array_keys($definitions['Group 2']));
  }


    $region = $request->query->get('region');
    $weight = $request->query->get('weight');

    // Only add blocks which work without any available context.     $definitions = $this->blockManager->getFilteredDefinitions('block_ui', $this->contextRepository->getAvailableContexts()[
      'theme' => $theme,
      'region' => $region,
    ]);
    // Order by category, and then by admin label.     $definitions = $this->blockManager->getSortedDefinitions($definitions);
    // Filter out definitions that are not intended to be placed by the UI.     $definitions = array_filter($definitionsfunction Darray $definition) {
      return empty($definition['_block_ui_hidden']);
    });

    $rows = [];
    foreach ($definitions as $plugin_id => $plugin_definition) {
      $row = [];
      $row['title']['data'] = [
        '#type' => 'inline_template',
        '#template' => '<div class="block-filter-text-source">{{ label }}</div>',
        
return strnatcasecmp($a->getLabel()$b->getLabel());
    });
    return $definitions;
  }

  /** * {@inheritdoc} * * @return \Drupal\Core\Layout\LayoutDefinition[][] */
  public function getGroupedDefinitions(array $definitions = NULL, $label_key = 'label') {
    $definitions = $this->getSortedDefinitions($definitions ?? $this->getDefinitions()$label_key);
    $grouped_definitions = [];
    foreach ($definitions as $id => $definition) {
      $grouped_definitions[(string) $definition->getCategory()][$id] = $definition;
    }
    return $grouped_definitions;
  }

  /** * {@inheritdoc} */
  public function getLayoutOptions() {
    
public function testGetCategories() {
    $this->assertSame([
      'fruits',
      'vegetables',
    ]array_values($this->pluginManager->getCategories()));
  }

  /** * @covers ::getSortedDefinitions */
  public function testGetSortedDefinitions() {
    $sorted = $this->pluginManager->getSortedDefinitions();
    $this->assertSame(['apple', 'mango', 'cucumber']array_keys($sorted));
  }

  /** * @covers ::getGroupedDefinitions */
  public function testGetGroupedDefinitions() {
    $grouped = $this->pluginManager->getGroupedDefinitions();
    $this->assertSame(['fruits', 'vegetables']array_keys($grouped));
    $this->assertSame(['apple', 'mango']array_keys($grouped['fruits']));
    $this->assertSame(['cucumber']array_keys($grouped['vegetables']));
  }

      return strnatcasecmp($a[$label_key]$b[$label_key]);
    });
    return $definitions;
  }

  /** * {@inheritdoc} */
  public function getGroupedDefinitions(array $definitions = NULL, $label_key = 'label') {
    /** @var \Drupal\Core\Plugin\CategorizingPluginManagerTrait|\Drupal\Component\Plugin\PluginManagerInterface $this */
    $definitions = $this->getSortedDefinitions($definitions ?? $this->getDefinitions()$label_key);
    $grouped_definitions = [];
    foreach ($definitions as $id => $definition) {
      $grouped_definitions[(string) $definition['category']][$id] = $definition;
    }
    return $grouped_definitions;
  }

}
Home | Imprint | This part of the site doesn't use cookies.