Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
… into feat/SLB-307
  • Loading branch information
HagerDakroury committed May 22, 2024
2 parents a9a8801 + 7a5eda5 commit 2bafa02
Show file tree
Hide file tree
Showing 23 changed files with 822 additions and 230 deletions.
6 changes: 4 additions & 2 deletions apps/cms/config/sync/entity_usage.settings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@ local_task_enabled_entity_types:
- node
track_enabled_source_entity_types:
- node
- content_moderation_state
- block_content
- content_moderation_state
- menu_link_content
- media
- redirect
- shortcut
- path_alias
track_enabled_target_entity_types:
- node
- content_moderation_state
- block_content
- content_moderation_state
- menu_link_content
- media
- redirect
Expand All @@ -32,6 +32,8 @@ track_enabled_plugins:
- html_link
- ckeditor_image
- block_field
- gutenberg_linked_content
- gutenberg_referenced_content
- gutenberg_media_embed
track_enabled_base_fields: false
site_domains: { }
Expand Down
2 changes: 1 addition & 1 deletion apps/cms/config/sync/linkit.linkit_profile.gutenberg.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@ matchers:
bundles:
document: document
group_by_bundle: 0
substitution_type: null
substitution_type: canonical
limit: '100'
weight: -9
1 change: 1 addition & 0 deletions apps/preview/.lagoon.env
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
PROJECT_NAME="example"
DRUPAL_URL="https://nginx.${LAGOON_ENVIRONMENT}.${LAGOON_PROJECT}.ch4.amazee.io"
71 changes: 71 additions & 0 deletions packages/drupal/custom/custom.module
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Language\LanguageInterface;
use Drupal\Core\Render\Element;
use Drupal\Core\Render\RenderContext;
use Drupal\Core\StreamWrapper\LocalStream;
use Drupal\Core\StreamWrapper\StreamWrapperInterface;
use Drupal\Core\Utility\Error as ErrorUtil;
use Drupal\file\Entity\File;
use Drupal\media\Entity\Media;
Expand Down Expand Up @@ -90,6 +92,75 @@ function custom_silverback_gutenberg_link_processor_outbound_url_alter(
}
}

/**
* Implements hook_silverback_gutenberg_link_processor_inbound_link_alter().
* @param \DOMElement $link
* @param \Drupal\silverback_gutenberg\LinkProcessor $linkProcessor
*
* @return void
* @throws \Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException
* @throws \Drupal\Component\Plugin\Exception\PluginNotFoundException
*/
function custom_silverback_gutenberg_link_processor_inbound_link_alter(
\DOMElement $link,
LinkProcessor $linkProcessor
) {
// For inbound links (when data gets saved), if the link points to a public
// file, then we want to replace the href value with "media/uuid/edit" and
// also make sure the data-id and data-entity-type attributes have the proper
// values (the uuid and the 'media' value). This is a special case for media,
// because the url of the media item is replaced by
// custom_silverback_gutenberg_link_processor_outbound_url_alter() with the
// file path, so now on inbound we need to basically do the opposite. This is
// needed so that the entity usage integration works properly (where the
// data-id and data-entity-type attributes are checked).
$href = $link->getAttribute('href');
/* @var \Drupal\Core\StreamWrapper\StreamWrapperManager $wrapperManager */
$wrapperManager = \Drupal::service('stream_wrapper_manager');
/* @var \Drupal\Core\StreamWrapper\StreamWrapperInterface[] $visibleWrappers */
$visibleWrappers = $wrapperManager->getWrappers(StreamWrapperInterface::VISIBLE);
foreach ($visibleWrappers as $scheme => $wrapperInfo) {
$wrapper = $wrapperManager->getViaScheme($scheme);
// We are only handle local streams for now.
if (!$wrapper instanceof LocalStream) {
continue;
}
if (!str_starts_with($href, '/' . $wrapper->getDirectoryPath() . '/')) {
continue;
}
// When searching for a file inside the database, the wrapper uri is used
// instead of the directory path. That is why we need the wrapper in the
// first place.
$fileuri = str_replace('/' . $wrapper->getDirectoryPath() . '/', $wrapper->getUri(), urldecode($href));
$files = \Drupal::entityTypeManager()
->getStorage('file')
->loadByProperties(['uri' => $fileuri]);
// No files found, just continue to the next wrapper.
if (empty($files)) {
continue;
}
$file = array_shift($files);
$usageList = \Drupal::service('file.usage')->listUsage($file);
// If the media file usage list is empty, then this is probably some kind of
// orphan file, or tracked by some other entity type.
if (empty($usageList['file']['media'])) {
continue;
}
$mids = array_keys($usageList['file']['media']);
$mid = reset($mids);
$media = Media::load($mid);
if (empty($media)) {
continue;
}
// If we got here, we found a matching media item, so we can populate the
// link metadata with its values and just break out of the wrappers loop.
$link->setAttribute('href', '/media/' . $media->uuid() . '/edit');
$link->setAttribute('data-id', $media->uuid());
$link->setAttribute('data-entity-type', 'media');
break;
}
}

/**
* Implements hook_form_alter().
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,9 @@ registerBlockType('custom/info-grid-item', {
)}
</div>
<InnerBlocks
templateLock={false}
templateLock={'all'}
allowedBlocks={['custom/heading', 'core/paragraph', 'custom/cta']}
template={[['custom/heading'], ['core/paragraph'], ['custom/cta']]}
/>
</div>
</>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ _meta:
uuid: 25086be7-ca5f-4ff8-9695-b9c71a676d4e
bundle: page
default_langcode: en
depends:
b998ae5e-8b56-40ca-8f80-fd4404e7e716: media
default:
revision_uid:
-
Expand Down Expand Up @@ -47,7 +49,7 @@ default:
<!-- wp:custom/content -->
<!-- wp:paragraph -->
<p><a href="/sites/default/files/2023-04/document_docx.docx" data-type="Media: Document" data-id="b998ae5e-8b56-40ca-8f80-fd4404e7e716">link to file</a></p>
<p><a href="/sites/default/files/2023-04/document_docx.docx" data-type="Media: Document" data-id="1" data-entity-type="media">link to file</a></p>
<!-- /wp:paragraph -->
<!-- wp:paragraph -->
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
_meta:
version: '1.0'
entity_type: node
uuid: 3164a225-df20-4794-8cfc-b7cd81cfde58
bundle: page
default_langcode: en
depends:
3a0fe860-a6d6-428a-9474-365bd57509aa: media
default:
revision_uid:
-
target_id: 1
status:
-
value: true
uid:
-
target_id: 1
title:
-
value: 'Info grid'
created:
-
value: 1716194667
promote:
-
value: false
sticky:
-
value: false
moderation_state:
-
value: published
path:
-
alias: /info-grid
langcode: en
pathauto: 0
content_translation_source:
-
value: und
content_translation_outdated:
-
value: false
body:
-
value: |-
<!-- wp:custom/hero {"mediaEntityIds":["3a0fe860-a6d6-428a-9474-365bd57509aa"],"headline":"Info grid","lead":"This is a page for info grid"} /-->
<!-- wp:custom/content -->
<!-- wp:custom/info-grid -->
<!-- wp:custom/info-grid-item {"icon":"EMAIL"} -->
<!-- wp:custom/heading {"text":"I am a heading"} -->
<h2 class="wp-block-custom-heading">I am a heading</h2>
<!-- /wp:custom/heading -->
<!-- wp:paragraph -->
<p>I am the body</p>
<!-- /wp:paragraph -->
<!-- wp:custom/cta {"text":"Link text"} /-->
<!-- /wp:custom/info-grid-item -->
<!-- wp:custom/info-grid-item {"icon":"PHONE"} -->
<!-- wp:custom/heading {"text":"I am second heading"} -->
<h2 class="wp-block-custom-heading">I am second heading</h2>
<!-- /wp:custom/heading -->
<!-- wp:paragraph -->
<p>I am the second body</p>
<!-- /wp:paragraph -->
<!-- wp:custom/cta {"text":"Second link text"} /-->
<!-- /wp:custom/info-grid-item -->
<!-- wp:custom/info-grid-item {"icon":"LIFE-RING"} -->
<!-- wp:custom/heading {"text":"I am the third heading"} -->
<h2 class="wp-block-custom-heading">I am the third heading</h2>
<!-- /wp:custom/heading -->
<!-- wp:paragraph -->
<p>I am the third body</p>
<!-- /wp:paragraph -->
<!-- wp:custom/cta {"text":"third link text"} /-->
<!-- /wp:custom/info-grid-item -->
<!-- /wp:custom/info-grid -->
<!-- wp:custom/info-grid -->
<!-- wp:custom/info-grid-item -->
<!-- wp:custom/heading {"text":"Just one info grid"} -->
<h2 class="wp-block-custom-heading">Just one info grid</h2>
<!-- /wp:custom/heading -->
<!-- wp:paragraph -->
<p></p>
<!-- /wp:paragraph -->
<!-- wp:custom/cta /-->
<!-- /wp:custom/info-grid-item -->
<!-- /wp:custom/info-grid -->
<!-- wp:custom/info-grid -->
<!-- wp:custom/info-grid-item -->
<!-- wp:custom/heading -->
<h2 class="wp-block-custom-heading"></h2>
<!-- /wp:custom/heading -->
<!-- wp:paragraph -->
<p></p>
<!-- /wp:paragraph -->
<!-- wp:custom/cta /-->
<!-- /wp:custom/info-grid-item -->
<!-- wp:custom/info-grid-item -->
<!-- wp:custom/heading -->
<h2 class="wp-block-custom-heading"></h2>
<!-- /wp:custom/heading -->
<!-- wp:paragraph -->
<p></p>
<!-- /wp:paragraph -->
<!-- wp:custom/cta /-->
<!-- /wp:custom/info-grid-item -->
<!-- wp:custom/info-grid-item -->
<!-- wp:custom/heading -->
<h2 class="wp-block-custom-heading"></h2>
<!-- /wp:custom/heading -->
<!-- wp:paragraph -->
<p></p>
<!-- /wp:paragraph -->
<!-- wp:custom/cta /-->
<!-- /wp:custom/info-grid-item -->
<!-- /wp:custom/info-grid -->
<!-- /wp:custom/content -->
format: gutenberg
summary: ''
Loading

0 comments on commit 2bafa02

Please sign in to comment.