Skip to content

Commit

Permalink
1145: Added block content fixtures
Browse files Browse the repository at this point in the history
  • Loading branch information
rimi-itk committed Apr 13, 2024
1 parent ec93d9e commit 6467f87
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
services:
Drupal\hoeringsportal_project_fixtures\Fixture\BlockContentFixture:
tags:
- { name: content_fixture }

Drupal\hoeringsportal_project_fixtures\Fixture\ProjectMainPageFixture:
tags:
- { name: content_fixture }
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?php

namespace Drupal\hoeringsportal_project_fixtures\Fixture;

use Drupal\block_content\Entity\BlockContent;
use Drupal\content_fixtures\Fixture\AbstractFixture;
use Drupal\content_fixtures\Fixture\FixtureGroupInterface;

/**
* Block content fixture.
*
* @package Drupal\hoeringsportal_project_fixtures\Fixture
*/
class BlockContentFixture extends AbstractFixture implements FixtureGroupInterface {

/**
* {@inheritdoc}
*/
public function load() {
$entity = BlockContent
::create([
'type' => 'aside_contact_info',
])
->setInfo('The main address')
->set('field_department', 'Redundancy Department')
->set('field_title', 'Department of Redundancy Department')
->set('body', [
'value' => '<p>Department<br>Street No.<br>1234</p>',
])
->set('field_phone_number', 1234567890)
->set('field_email', '[email protected]');

$entity->save();
$this->addReference('block_content:the_main_address', $entity);

$entity = BlockContent
::create([
'type' => 'aside_contact_info',
])
->setInfo('Another address')
->set('field_department', 'The Department')
->set('field_title', 'Title of the Department')
->set('body', [
'value' => '<p>Street 87</p>',
])
->set('field_phone_number', 2234455)
->set('field_email', '[email protected]');

$entity->save();
$this->addReference('block_content:another_address', $entity);
}

/**
* {@inheritdoc}
*/
public function getGroups() {
return ['block', 'project'];
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,10 @@ public function load() {
BODY,
'format' => 'filtered_html',
],
);
)
->set('field_aside_block', [
['target_id' => $this->getReference('block_content:the_main_address')->id()],
]);

$paragraph = Paragraph::create([
'type' => 'image',
Expand Down Expand Up @@ -103,13 +106,41 @@ public function load() {
);
$entity->save();
$this->addReference('node:project_main_page:2', $entity);

$entity = $entity->createDuplicate();
$entity
->setTitle('The third project')
->set('field_short_description', 'We have more than one project')
->set(
'field_project_image',
[
['target_id' => $this->getReference('media:Map1')->id()],
]
)
->set(
'body',
[
'value' => <<<'BODY'
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed luctus accumsan ante sit amet fermentum. Aliquam aliquet massa ut enim vulputate feugiat. Maecenas tincidunt risus rhoncus, interdum neque ac, aliquet ex. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia curae; Cras commodo, odio id scelerisque pulvinar, erat neque fringilla purus, non faucibus metus nibh ullamcorper arcu. In posuere magna ante, in cursus velit lacinia eu. Sed viverra blandit sem. Donec quam orci, tincidunt eget porttitor at, luctus eu est. In sed nulla mauris. Etiam arcu augue, accumsan vitae magna vel, interdum imperdiet magna.</p>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed luctus accumsan ante sit amet fermentum. Aliquam aliquet massa ut enim vulputate feugiat. Maecenas tincidunt risus rhoncus, interdum neque ac, aliquet ex. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia curae; Cras commodo, odio id scelerisque pulvinar, erat neque fringilla purus, non faucibus metus nibh ullamcorper arcu. In posuere magna ante, in cursus velit lacinia eu. Sed viverra blandit sem. Donec quam orci, tincidunt eget porttitor at, luctus eu est. In sed nulla mauris. Etiam arcu augue, accumsan vitae magna vel, interdum imperdiet magna.
</p>
BODY,
'format' => 'filtered_html',
],
)
->set('field_aside_block', [
['target_id' => $this->getReference('block_content:another_address')->id()],
]);
;
$entity->save();
}

/**
* {@inheritdoc}
*/
public function getDependencies() {
return [
BlockContentFixture::class,
MediaFixture::class,
ParagraphFixture::class,
];
Expand Down

0 comments on commit 6467f87

Please sign in to comment.