Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/craft-4' into craft-5
Browse files Browse the repository at this point in the history
# Conflicts:
#	CHANGELOG.md
#	composer.json
  • Loading branch information
engram-design committed Apr 12, 2024
2 parents ceadb60 + 81ffdec commit a990a75
Show file tree
Hide file tree
Showing 18 changed files with 220 additions and 69 deletions.
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,20 @@
- Now requires PHP `8.2.0+`.
- Now requires Craft `5.0.0-beta.1+`.

## 1.0.4 - 2024-03-18

### Added
- Add support for Hyper fields

### Fixed
- Fix some fields like Hyper and Vizy not showing in preview correctly.
- Fix display of importing deleted elements.
- Fix deleted/restored elements not exporting correctly.
- Fix an error when importing users and permissions.
- Fix some errors when importing assets where folders or file cannot be found.
- Fix an error when trying to preview an element with no parent.
- Fix an error for non-English sites.

## 1.0.3 - 2024-03-04

### Fixed
Expand Down
56 changes: 28 additions & 28 deletions config.codekit3
Original file line number Diff line number Diff line change
Expand Up @@ -689,59 +689,59 @@
"oAP" : "\/src\/web\/assets\/app\/dist\/assets\/success-large-9c1960a9.js.map.gz",
"oF" : 0
},
"\/src\/web\/assets\/app\/dist\/assets\/zen-d2f702f3.css" : {
"aP" : 1,
"bl" : 0,
"ci" : 0,
"co" : 0,
"ft" : 16,
"ma" : 0,
"oA" : 0,
"oAP" : "\/src\/web\/assets\/app\/dist\/assets\/zen-d2f702f3-min.css",
"oF" : 0,
"pg" : 0
},
"\/src\/web\/assets\/app\/dist\/assets\/zen-d2f702f3.css.gz" : {
"cB" : 0,
"ft" : 8192,
"hM" : 0,
"oA" : 2,
"oAP" : "\/src\/web\/assets\/app\/dist\/assets\/zen-d2f702f3.css.gz",
"oF" : 0
},
"\/src\/web\/assets\/app\/dist\/assets\/zen-ff4e00cd.js" : {
"\/src\/web\/assets\/app\/dist\/assets\/zen-8e98a6c7.js" : {
"bF" : 0,
"ft" : 64,
"ma" : 1,
"mi" : 1,
"oA" : 0,
"oAP" : "\/src\/web\/assets\/app\/dist\/js\/zen-ff4e00cd.js",
"oAP" : "\/src\/web\/assets\/app\/dist\/js\/zen-8e98a6c7.js",
"oF" : 0,
"sC" : 0,
"tS" : 0
},
"\/src\/web\/assets\/app\/dist\/assets\/zen-ff4e00cd.js.gz" : {
"\/src\/web\/assets\/app\/dist\/assets\/zen-8e98a6c7.js.gz" : {
"cB" : 0,
"ft" : 8192,
"hM" : 0,
"oA" : 2,
"oAP" : "\/src\/web\/assets\/app\/dist\/assets\/zen-ff4e00cd.js.gz",
"oAP" : "\/src\/web\/assets\/app\/dist\/assets\/zen-8e98a6c7.js.gz",
"oF" : 0
},
"\/src\/web\/assets\/app\/dist\/assets\/zen-ff4e00cd.js.map" : {
"\/src\/web\/assets\/app\/dist\/assets\/zen-8e98a6c7.js.map" : {
"cB" : 0,
"ft" : 8192,
"hM" : 0,
"oA" : 2,
"oAP" : "\/src\/web\/assets\/app\/dist\/assets\/zen-ff4e00cd.js.map",
"oAP" : "\/src\/web\/assets\/app\/dist\/assets\/zen-8e98a6c7.js.map",
"oF" : 0
},
"\/src\/web\/assets\/app\/dist\/assets\/zen-ff4e00cd.js.map.gz" : {
"\/src\/web\/assets\/app\/dist\/assets\/zen-8e98a6c7.js.map.gz" : {
"cB" : 0,
"ft" : 8192,
"hM" : 0,
"oA" : 2,
"oAP" : "\/src\/web\/assets\/app\/dist\/assets\/zen-ff4e00cd.js.map.gz",
"oAP" : "\/src\/web\/assets\/app\/dist\/assets\/zen-8e98a6c7.js.map.gz",
"oF" : 0
},
"\/src\/web\/assets\/app\/dist\/assets\/zen-d2f702f3.css" : {
"aP" : 1,
"bl" : 0,
"ci" : 0,
"co" : 0,
"ft" : 16,
"ma" : 0,
"oA" : 0,
"oAP" : "\/src\/web\/assets\/app\/dist\/assets\/zen-d2f702f3-min.css",
"oF" : 0,
"pg" : 0
},
"\/src\/web\/assets\/app\/dist\/assets\/zen-d2f702f3.css.gz" : {
"cB" : 0,
"ft" : 8192,
"hM" : 0,
"oA" : 2,
"oAP" : "\/src\/web\/assets\/app\/dist\/assets\/zen-d2f702f3.css.gz",
"oF" : 0
},
"\/src\/web\/assets\/app\/dist\/manifest.json" : {
Expand Down
24 changes: 21 additions & 3 deletions src/base/Element.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ public static function defineImportTableAttributes(): array
public static function getImportTableValues(array $diffCounts, ?ElementInterface $newElement, ?ElementInterface $currentElement, ?string $state): array
{
$element = $newElement ?? $currentElement ?? null;
$parent = $element ? $element->getParent() : null;
$elementHtml = $element ? static::getElementHtml($element) : '';
$elementColumns = [];

Expand All @@ -147,7 +148,7 @@ public static function getImportTableValues(array $diffCounts, ?ElementInterface
$prefixColumns = [
'id' => $elementId,
'element' => $elementHtml,
'parents' => static::getParentSummary($element->getParent()),
'parents' => static::getParentSummary($parent),
'site' => $element->site->name ?? '',
];

Expand Down Expand Up @@ -490,9 +491,10 @@ public static function defineEagerLoadingMap(): array
return [];
}

public static function generateCompareHtml(?ElementInterface $element, array $diffSummary, string $type): string
public static function generateCompareHtml(?ElementInterface $element, array $diffSummary, string $type): array
{
$html = '';
$js = '';
$view = Craft::$app->getView();

// Required when testing outside of the CP (using the URLs directly)
Expand All @@ -509,7 +511,10 @@ public static function generateCompareHtml(?ElementInterface $element, array $di
$fieldsService->getFieldForPreview($field, $element, $type);
}

// Render the form, despite us not needing the HTML, we need to fetch any JS used to append it
Craft::$app->getView()->startJsBuffer();
$form = $fieldLayout->createForm($element, true);
$js = Craft::$app->getView()->clearJsBuffer();

// Get any custom field tabs for the element, and any extra defined class
$tabHtml = '';
Expand Down Expand Up @@ -552,6 +557,19 @@ public static function generateCompareHtml(?ElementInterface $element, array $di
$url = $view->getAssetManager()->getActualAssetUrl($bundle, $cssFile);
$html .= '<link href="' . $url . '" rel="stylesheet">';
}

foreach ($bundle->js as $jsFile) {
$type = 'script';

if (is_array($jsFile)) {
$type = $jsFile['type'] ?? $type;

$jsFile = $jsFile[array_keys($jsFile)[0]];
}

$url = $view->getAssetManager()->getActualAssetUrl($bundle, $jsFile);
$js = '<script type="' . $type . '" src="' . $url . '"></script>' . $js;
}
}
}

Expand Down Expand Up @@ -624,7 +642,7 @@ public static function generateCompareHtml(?ElementInterface $element, array $di
// Fix dropdown fields (selectize) being hidden
$crawler->filter('.selectize.select select')->removeAttribute('style');

return $crawler->saveHTML();
return ['html' => $crawler->saveHTML(), 'js' => $js];
}


Expand Down
23 changes: 14 additions & 9 deletions src/elements/Asset.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,19 +86,24 @@ public static function defineSerializedElement(ElementInterface $element, array
$data['focalPoint'] = $element->focalPoint;
}

$data['folder'] = [
'volume' => $element->getFolder()->volumeId,
'name' => $element->getFolder()->name,
'path' => $element->getFolder()->path,
];
if ($element->folderId && $folder = $element->getFolder()) {
$data['folder'] = [
'volume' => $folder->volumeId,
'name' => $folder->name,
'path' => $folder->path,
];
}

// If serializing for an export, record any additional files (the actual asset) to be stored in the zip
// But only for local storage. If a remote filesystem, no need to process
if ($element->getVolume()->getFs() instanceof Local) {
Zen::$plugin->getExport()->storeExportFile([
'filename' => $element->filename,
'content' => $element->getContents(),
]);
// Check if the file actually exists. Soft-deleted assets have their files hard-deleted
if ($element->getVolume()->fileExists($element->getPath())) {
Zen::$plugin->getExport()->storeExportFile([
'filename' => $element->filename,
'content' => $element->getContents(),
]);
}
}

return $data;
Expand Down
2 changes: 1 addition & 1 deletion src/elements/GlobalSet.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ public static function defineImportFieldTabs(ElementInterface $element, string $
];
}

public static function generateCompareHtml(?ElementInterface $element, array $diffs, string $type): string
public static function generateCompareHtml(?ElementInterface $element, array $diffs, string $type): array
{
// Special-case to fetch the same field layout which isn't carried over
if ($type == 'new') {
Expand Down
5 changes: 4 additions & 1 deletion src/elements/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,10 @@ public static function defineSerializedElement(ElementInterface $element, array
$data['fullName'] = $element->fullName;
$data['friendlyName'] = $element->friendlyName;
$data['groupUids'] = ArrayHelper::getColumn($element->getGroups(), 'uid');
$data['permissions'] = Craft::$app->getUserPermissions()->getPermissionsByUserId($element->id);

if ($element->id) {
$data['permissions'] = Craft::$app->getUserPermissions()->getPermissionsByUserId($element->id);
}

if ($photo = $element->getPhoto()) {
$data['photo'] = Asset::getSerializedElement($photo);
Expand Down
63 changes: 63 additions & 0 deletions src/fields/Hyper.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<?php
namespace verbb\zen\fields;

use verbb\zen\base\Field as ZenField;

use Craft;
use craft\base\ElementInterface;
use craft\base\FieldInterface;
use craft\db\Table;
use craft\helpers\Db;

use verbb\hyper\fields\HyperField;
use verbb\hyper\base\ElementLink;

class Hyper extends ZenField
{
// Static Methods
// =========================================================================

public static function fieldType(): string
{
return HyperField::class;
}

public static function serializeValue(FieldInterface $field, ElementInterface $element, mixed $value): mixed
{
$value = $field->serializeValue($value, $element);

if (is_array($value)) {
foreach ($value as $key => $link) {
if (is_subclass_of($link['type'], ElementLink::class)) {
// Swap IDs for UIDs
$linkSiteId = $link['linkSiteId'] ?? null;
$linkValue = $link['linkValue'] ?? null;

$value[$key]['linkSiteId'] = $linkSiteId ? Db::uidById(Table::SITES, $linkSiteId) : null;
$value[$key]['linkValue'] = $linkValue ? Db::uidById(Table::ELEMENTS, $linkValue) : null;
}
}
}

return $value;
}

public static function normalizeValue(FieldInterface $field, ElementInterface $element, mixed $value): mixed
{
if (is_array($value)) {
foreach ($value as $key => $link) {
if (is_subclass_of($link['type'], ElementLink::class)) {
// Swap UIDs for IDs
$linkSiteId = $link['linkSiteId'] ?? null;
$linkValue = $link['linkValue'] ?? null;

$value[$key]['linkSiteId'] = $linkSiteId ? Db::idByUid(Table::SITES, $linkSiteId) : null;
$value[$key]['linkValue'] = $linkValue ? Db::idByUid(Table::ELEMENTS, $linkValue) : null;
}
}
}

return $value;
}

}
22 changes: 19 additions & 3 deletions src/services/Export.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use craft\base\Component;
use craft\helpers\Db;
use craft\helpers\Json;
use craft\helpers\StringHelper;

use DateTime;

Expand Down Expand Up @@ -39,9 +40,13 @@ public function getExportOptions(DateTime $fromDate, DateTime $toDate): array
// For each item, add a prefix to the `value` param to allow us to record what type of element it's for.
$this->_decorateElementOptionValues($elementType::exportKey(), $elements);

// Ge tthe display name for the element from the class, otherwise it'll be translated
$classNameParts = explode('\\', $elementType);
$displayName = StringHelper::toCamelCase(array_pop($classNameParts));

$options[] = [
'label' => $elementType::pluralDisplayName(),
'value' => $elementType::pluralLowerDisplayName(),
'value' => $displayName,
'count' => array_sum(ArrayHelper::getColumn($elements, 'count')),
'children' => $elements,
];
Expand Down Expand Up @@ -107,8 +112,19 @@ public function getExportData(array $elements, DateTime $fromDate, DateTime $toD
}

// Also need to do a separate call for deleted/restored elements and store separately
$json[$elementType]['deleted'] = $elementsService->getDeletedElementsForExport($elementType::elementType(), $dateRange, $elementCriteria);
$json[$elementType]['restored'] = $elementsService->getRestoredElementsForExport($elementType::elementType(), $dateRange, $elementCriteria);
$currentDeletedElements = $json[$elementType]['deleted'] ?? [];
$newDeletedElements = $elementsService->getDeletedElementsForExport($elementType::elementType(), $dateRange, $elementCriteria);

if ($newDeletedElements) {
$json[$elementType]['deleted'] = array_merge($currentDeletedElements, $newDeletedElements);
}

$currentRestoredElements = $json[$elementType]['restored'] ?? [];
$newRestoredElements = $elementsService->getRestoredElementsForExport($elementType::elementType(), $dateRange, $elementCriteria);

if ($newRestoredElements) {
$json[$elementType]['restored'] = array_merge($currentRestoredElements, $newRestoredElements);
}
}
}

Expand Down
4 changes: 4 additions & 0 deletions src/services/Fields.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ public function getAllFieldTypes(): array
$fieldTypes[] = fieldTypes\Preparse::class;
}

if (Plugin::isPluginInstalledAndEnabled('hyper')) {
$fieldTypes[] = fieldTypes\Hyper::class;
}

$event = new RegisterComponentTypesEvent([
'types' => $fieldTypes,
]);
Expand Down
Loading

0 comments on commit a990a75

Please sign in to comment.