Skip to content

Commit

Permalink
Merge pull request #187 from steverowling/features/multisite-entry-li…
Browse files Browse the repository at this point in the history
…nking

- Add ability to link to entries in different sites
- Fix #53
- Fix #92
  • Loading branch information
andris-sevcenko authored Dec 11, 2019
2 parents e73a1a3 + b9bfa59 commit c949607
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 9 deletions.
16 changes: 10 additions & 6 deletions src/Field.php
Original file line number Diff line number Diff line change
Expand Up @@ -469,10 +469,10 @@ function(array $matches) use ($allowedStyles) {

// Find any element URLs and swap them with ref tags
$value = preg_replace_callback(
'/(href=|src=)([\'"])[^\'"#]+?(#[^\'"#]+)?(?:#|%23)([\w\\\\]+)\:(\d+)(\:(?:transform\:)?'.HandleValidator::$handlePattern.')?\2/',
'/(href=|src=)([\'"])[^\'"#]+?(#[^\'"#]+)?(?:#|%23)([\w\\\\]+)\:(\d+)(?:@(\d+))?(\:(?:transform\:)?'.HandleValidator::$handlePattern.')?\2/',
function($matches) {
// Create the ref tag, and make sure :url is in there
$refTag = '{'.$matches[4].':'.$matches[5].(!empty($matches[6]) ? $matches[6] : ':url').'}';
$refTag = '{'.$matches[4].':'.$matches[5].(!empty($matches[6]) ? '@'.$matches[6] : '').(!empty($matches[7]) ? $matches[7] : ':url').'}';
$hash = (!empty($matches[3]) ? $matches[3] : '');

if ($hash) {
Expand Down Expand Up @@ -514,7 +514,7 @@ private function _parseRefs(string $value, ElementInterface $element = null): st
return $value;
}

return preg_replace_callback('/(href=|src=)([\'"])(\{([\w\\\\]+\:\d+\:(?:transform\:)?'.HandleValidator::$handlePattern.')\})(#[^\'"#]+)?\2/', function($matches) use ($element) {
return preg_replace_callback('/(href=|src=)([\'"])(\{([\w\\\\]+\:\d+(?:@\d+)?\:(?:transform\:)?'.HandleValidator::$handlePattern.')\})(#[^\'"#]+)?\2/', function($matches) use ($element) {
/** @var Element|null $element */
list (, $attr, $q, $refTag, $ref) = $matches;
$fragment = $matches[5] ?? '';
Expand Down Expand Up @@ -591,14 +591,18 @@ private function _getSectionSources(Element $element = null): array
$sections = Craft::$app->getSections()->getAllSections();
$showSingles = false;

// Get all sites
$sites = Craft::$app->getSites()->getAllSites();

foreach ($sections as $section) {
if ($section->type === Section::TYPE_SINGLE) {
$showSingles = true;
} else if ($element) {
// Does the section have URLs in the same site as the element we're editing?
$sectionSiteSettings = $section->getSiteSettings();
if (isset($sectionSiteSettings[$element->siteId]) && $sectionSiteSettings[$element->siteId]->hasUrls) {
$sources[] = 'section:'.$section->uid;
foreach ($sites as $site) {
if (isset($sectionSiteSettings[$site->id]) && $sectionSiteSettings[$site->id]->hasUrls) {
$sources[] = 'section:'.$section->uid;
}
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/assets/field/dist/js/CraftEntryLinks.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ var plugin = $.extend({}, Craft.Redactor.PluginBase, {
var element = elements[0],
selection = this.app.selection.getText(),
data = {
url: element.url + '#' + refHandle + ':' + element.id,
url: element.url + '#' + refHandle + ':' + element.id + '@' + element.siteId,
text: selection.length > 0 ? selection : element.label
};
this.app.api('module.link.insert', data);
Expand Down
2 changes: 1 addition & 1 deletion src/assets/field/dist/js/CraftEntryLinks.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/assets/field/dist/js/CraftEntryLinks.min.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit c949607

Please sign in to comment.