Skip to content
Snippets Groups Projects
Verified Commit eef17400 authored by Théodore Biadala's avatar Théodore Biadala
Browse files

Issue #3062376 by smustgrave, rlnorthcutt, Krzysztof Domański, ravi.shankar,...

Issue #3062376 by smustgrave, rlnorthcutt, Krzysztof Domański, ravi.shankar, robpowell, acbramley, Abhijith S, larowlan, Anybody, lauriii, phenaproxima, brandonratz, danflanagan8, quietone, longwave: Template suggestions for custom block view modes

(cherry picked from commit b050dbf4)
parent e5cd97f1
No related branches found
No related tags found
26 merge requests!11185Issue #3477324 by andypost, alexpott: Fix usage of str_getcsv() and fgetcsv() for PHP 8.4,!10602Issue #3438769 by vinmayiswamy, antonnavi, michelle, amateescu: Sub workspace does not clear,!10301Issue #3469309 by mstrelan, smustgrave, moshe weitzman: Use one-time login...,!10187Issue #3487488 by dakwamine: ExtensionMimeTypeGuesser::guessMimeType must support file names with "0" (zero) like foo.0.zip,!9944Issue #3483353: Consider making the createCopy config action optionally fail...,!9929Issue #3445469 by pooja_sharma, smustgrave: Add additional test coverage for...,!9787Resolve issue 3479427 - bootstrap barrio issue under Windows,!9742Issue #3463908 by catch, quietone: Split OptionsFieldUiTest into two,!9526Issue #3458177 by mondrake, catch, quietone, godotislate, longwave, larowlan,...,!8738Issue #3424162 by camilledavis, dineshkumarbollu, smustgrave: Claro...,!8704Make greek characters available in ckeditor5,!8597Draft: Issue #3442259 by catch, quietone, dww: Reduce time of Migrate Upgrade tests...,!8533Issue #3446962 by kim.pepper: Remove incorrectly added...,!8517Issue #3443748 by NexusNovaz, smustgrave: Testcase creates false positive,!8325Update file Sort.php,!8095Expose document root on install,!7930Resolve #3427374 "Taxonomytid viewsargumentdefault plugin",!7627Issue #3439440 by nicxvan, Binoli Lalani, longwave: Remove country support from DateFormatter,!7445Issue #3440169: When using drupalGet(), provide an associative array for $headers,!7401#3271894 Fix documented StreamWrapperInterface return types for realpath() and dirname(),!7384Add constraints to system.advisories,!7078Issue #3320569 by Spokje, mondrake, smustgrave, longwave, quietone, Lendude,...,!6622Issue #2559833 by piggito, mohit_aghera, larowlan, guptahemant, vakulrai,...,!6502Draft: Resolve #2938524 "Plach testing issue",!38582585169-10.1.x,!3226Issue #2987537: Custom menu link entity type should not declare "bundle" entity key
Pipeline #107341 passed with warnings
Pipeline: drupal

#107350

    Pipeline: drupal

    #107345

      ...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
      * Allows the creation of content blocks through the user interface. * Allows the creation of content blocks through the user interface.
      */ */
      use Drupal\block_content\BlockContentInterface;
      use Drupal\Core\Url; use Drupal\Core\Url;
      use Drupal\Core\Routing\RouteMatchInterface; use Drupal\Core\Routing\RouteMatchInterface;
      use Drupal\field\Entity\FieldConfig; use Drupal\field\Entity\FieldConfig;
      ...@@ -183,3 +184,33 @@ function _block_content_has_reusable_condition(array $condition, array $tables) ...@@ -183,3 +184,33 @@ function _block_content_has_reusable_condition(array $condition, array $tables)
      } }
      return FALSE; return FALSE;
      } }
      /**
      * Implements hook_theme_suggestions_HOOK_alter() for block templates.
      */
      function block_content_theme_suggestions_block_alter(array &$suggestions, array $variables) {
      $suggestions_new = [];
      $content = $variables['elements']['content'];
      $block_content = $variables['elements']['content']['#block_content'] ?? NULL;
      if ($block_content instanceof BlockContentInterface) {
      $bundle = $content['#block_content']->bundle();
      $view_mode = strtr($variables['elements']['#configuration']['view_mode'], '.', '_');
      $suggestions_new[] = 'block__block_content__view__' . $view_mode;
      $suggestions_new[] = 'block__block_content__type__' . $bundle;
      $suggestions_new[] = 'block__block_content__view_type__' . $bundle . '__' . $view_mode;
      if (!empty($variables['elements']['#id'])) {
      $suggestions_new[] = 'block__block_content__id__' . $variables['elements']['#id'];
      $suggestions_new[] = 'block__block_content__id_view__' . $variables['elements']['#id'] . '__' . $view_mode;
      }
      // Remove duplicate block__block_content.
      $suggestions = array_unique($suggestions);
      array_splice($suggestions, 1, 0, $suggestions_new);
      }
      return $suggestions;
      }
      <?php
      namespace Drupal\Tests\block_content\Kernel;
      use Drupal\block\Entity\Block;
      use Drupal\block_content\Entity\BlockContent;
      use Drupal\block_content\Entity\BlockContentType;
      use Drupal\KernelTests\KernelTestBase;
      /**
      * Tests the block_content_theme_suggestions_block() function.
      *
      * @group block_content
      */
      class BlockTemplateSuggestionsTest extends KernelTestBase {
      /**
      * {@inheritdoc}
      */
      protected static $modules = [
      'user',
      'block',
      'block_content',
      'system',
      ];
      /**
      * The BlockContent entity used for testing.
      *
      * @var \Drupal\block_content\Entity\BlockContent
      */
      protected $blockContent;
      /**
      * {@inheritdoc}
      */
      protected function setUp(): void {
      parent::setUp();
      $this->installEntitySchema('block_content');
      // Create a block content type.
      $block_content_type = BlockContentType::create([
      'id' => 'test_block',
      'label' => 'A test block type',
      'description' => "Provides a test block type.",
      ]);
      $block_content_type->save();
      $this->blockContent = BlockContent::create([
      'info' => 'The Test Block',
      'type' => 'test_block',
      ]);
      $this->blockContent->save();
      }
      /**
      * Tests template suggestions from block_content_theme_suggestions_block().
      */
      public function testBlockThemeHookSuggestions() {
      // Create a block using a block_content plugin.
      $block = Block::create([
      'plugin' => 'block_content:' . $this->blockContent->uuid(),
      'region' => 'footer',
      'id' => 'machine_name',
      ]);
      $variables['elements']['#id'] = $block->id();
      $variables['elements']['#configuration']['provider'] = 'block_content';
      $variables['elements']['#configuration']['view_mode'] = 'full';
      $variables['elements']['content']['#block_content'] = $this->blockContent;
      $suggestions_empty = [];
      $suggestions_empty[] = 'block__block_content__' . $block->uuid();
      $suggestions = block_content_theme_suggestions_block_alter($suggestions_empty, $variables);
      $this->assertSame([
      'block__block_content__' . $block->uuid(),
      'block__block_content__view__full',
      'block__block_content__type__test_block',
      'block__block_content__view_type__test_block__full',
      'block__block_content__id__machine_name',
      'block__block_content__id_view__machine_name__full',
      ], $suggestions);
      }
      }
      0% Loading or .
      You are about to add 0 people to the discussion. Proceed with caution.
      Finish editing this message first!
      Please register or to comment