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 d751d50 + 4de9aed commit 422f44a
Show file tree
Hide file tree
Showing 21 changed files with 507 additions and 214 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 @@ -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
Expand Up @@ -7,47 +7,35 @@ _meta:
depends:
3a0fe860-a6d6-428a-9474-365bd57509aa: media
478c4289-961d-4ce8-85d6-578ae05f3019: media
72187a1f-3e48-4b45-a9b7-189c6fd7ee26: media
5dfc1856-e9e4-4f02-9cd6-9d888870ce1a: media
72187a1f-3e48-4b45-a9b7-189c6fd7ee26: media
default:
revision_uid:
-
target_id: 1
- target_id: 1
status:
-
value: true
- value: true
uid:
-
target_id: 1
- target_id: 1
title:
-
value: 'Blocks: complete'
- value: 'Blocks: complete'
created:
-
value: 1686759493
- value: 1686759493
promote:
-
value: false
- value: false
sticky:
-
value: false
- value: false
moderation_state:
-
value: published
- value: published
path:
-
alias: /blocks-complete
- alias: /blocks-complete
langcode: en
pathauto: 0
content_translation_source:
-
value: und
- value: und
content_translation_outdated:
-
value: false
- value: false
body:
-
value: |-
- value: |-
<!-- wp:custom/hero {"mediaEntityIds":["3a0fe860-a6d6-428a-9474-365bd57509aa"],"headline":"All kinds of blocks with maximum data","lead":"Lead text","ctaUrl":"https://example.com","ctaText":"CTA text","formId":"contact"} /-->
<!-- wp:custom/content -->
Expand Down Expand Up @@ -107,7 +95,7 @@ default:
<!-- /wp:quote -->
<!-- wp:custom/image-teasers -->
<!-- wp:custom/image-teaser {"mediaEntityIds":["3a0fe860-a6d6-428a-9474-365bd57509aa"],"title":"Teaser 1","ctaUrl":"https://google.com","ctaText":"Foo"} /-->
<!-- wp:custom/image-teaser {"mediaEntityIds":["5dfc1856-e9e4-4f02-9cd6-9d888870ce1a"],"title":"Teaser 1","ctaUrl":"https://google.com","ctaText":"Foo"} /-->
<!-- wp:custom/image-teaser {"mediaEntityIds":["72187a1f-3e48-4b45-a9b7-189c6fd7ee26"],"title":"Teaser 2","ctaUrl":"https://google.com","ctaText":"Bar"} /-->
<!-- /wp:custom/image-teasers -->
Expand Down Expand Up @@ -137,46 +125,82 @@ default:
<!-- /wp:paragraph -->
<!-- /wp:custom/accordion-item-text -->
<!-- /wp:custom/accordion -->
<!-- wp:custom/info-grid -->
<!-- wp:custom/info-grid-item {"icon":"EMAIL"} -->
<!-- wp:custom/heading {"level":3,"text":"Email us:"} -->
<h3 class="wp-block-custom-heading">Email us:</h3>
<!-- /wp:custom/heading -->
<!-- wp:paragraph -->
<p>Email us for general queries, including marketing and partnership opportunities.</p>
<!-- /wp:paragraph -->
<!-- wp:paragraph -->
<p><a href="mailto:[email protected]">[email protected]</a></p>
<!-- /wp:paragraph -->
<!-- wp:custom/cta {"url":"/en/page-links","text":"Nullam dictum felis","data-id":"25086be7-ca5f-4ff8-9695-b9c71a676d4e","data-entity-type":"node","icon":"ARROW"} /-->
<!-- /wp:custom/info-grid-item -->
<!-- wp:custom/info-grid-item {"icon":"PHONE"} -->
<!-- wp:custom/heading {"level":3,"text":"Call us:"} -->
<h3 class="wp-block-custom-heading">Call us:</h3>
<!-- /wp:custom/heading -->
<!-- wp:paragraph -->
<p>Call us to speak to a member of our team. We are always happy to help.</p>
<!-- /wp:paragraph -->
<!-- wp:paragraph -->
<p><a href="tel:+16467865060">+1 (646) 786-5060</a></p>
<!-- /wp:paragraph -->
<!-- wp:custom/cta {"url":"/en/technologies","text":"Duis lobortis massa","data-id":"3a026abf-39d5-4c81-a76e-6f30593f114d","data-entity-type":"node"} /-->
<!-- /wp:custom/info-grid-item -->
<!-- wp:custom/info-grid-item {"icon":"LIFE-RING"} -->
<!-- wp:custom/heading {"level":3,"text":"Support"} -->
<h3 class="wp-block-custom-heading">Support</h3>
<!-- /wp:custom/heading -->
<!-- wp:paragraph -->
<p>Check out helpful resources, FAQs and developer tools.</p>
<!-- /wp:paragraph -->
<!-- wp:custom/cta {"url":"http://www.google.com","text":"Nunc nulla","data-id":"http://www.google.com","data-entity-type":"","openInNewTab":true} /-->
<!-- /wp:custom/info-grid-item -->
<!-- /wp:custom/info-grid -->
<!-- /wp:custom/content -->
format: gutenberg
summary: ''
translations:
de:
status:
-
value: true
- value: true
uid:
-
target_id: 1
- target_id: 1
title:
-
value: 'Blocks: complete DE'
- value: 'Blocks: complete DE'
created:
-
value: 1687338353
- value: 1687338353
promote:
-
value: false
- value: false
sticky:
-
value: false
- value: false
moderation_state:
-
value: published
- value: published
path:
-
alias: /blocks-complete
- alias: /blocks-complete
langcode: de
pathauto: 0
content_translation_source:
-
value: en
- value: en
content_translation_outdated:
-
value: false
- value: false
body:
-
value: |-
- value: |-
<!-- wp:custom/hero {"mediaEntityIds":["3a0fe860-a6d6-428a-9474-365bd57509aa"],"headline":"All kinds of blocks with maximum data DE","lead":"Lead text DE"} /-->
<!-- wp:custom/content -->
Expand Down
13 changes: 13 additions & 0 deletions packages/schema/src/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,18 @@ enum CTAIconPosition {
BEFORE
}

type BlockImageWithText @type(id: "custom/image-with-text") {
image: MediaImage @resolveEditorBlockMedia
textContent: BlockMarkup @resolveEditorBlockChildren @seek(pos: 0)
}

type BlockQuote @type(id: "custom/quote") {
quote: Markup @resolveEditorBlockAttribute(key: "quote")
author: String @resolveEditorBlockAttribute(key: "author")
role: String @resolveEditorBlockAttribute(key: "role")
image: MediaImage @resolveEditorBlockMedia
}

type BlockImageWithText @type(id: "custom/image-with-text") {
image: MediaImage @resolveEditorBlockMedia
imagePosition: ImagePosition!
Expand All @@ -301,6 +313,7 @@ enum InfoGridIcon @default @value(string: "EMAIL") {
PHONE
LIFE_RING
}

type BlockInfoGrid @type(id: "custom/info-grid") {
gridItems: [BlockInfoGridItem]! @resolveEditorBlockChildren
}
Expand Down
3 changes: 1 addition & 2 deletions packages/ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,10 @@
"dependencies": {
"@amazeelabs/silverback-iframe": "^1.3.0",
"@custom/schema": "workspace:*",
"@headlessui/react": "^1.7.17",
"@headlessui/react": "^2.0.3",
"@heroicons/react": "^2.1.1",
"@hookform/resolvers": "^3.3.3",
"clsx": "^2.1.0",
"flowbite-react": "^0.9.0",
"framer-motion": "^10.17.4",
"hast-util-is-element": "^2.1.3",
"hast-util-select": "^5.0.5",
Expand Down
Loading

0 comments on commit 422f44a

Please sign in to comment.