Skip to content

Commit

Permalink
Merge pull request #1346 from craftcms/bugfix/1340-entrified-fields
Browse files Browse the repository at this point in the history
handle entrified categories and tags fields
  • Loading branch information
angrybrad committed Jul 6, 2023
2 parents 3fdc8a7 + 5fb9d50 commit b439f86
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/fields/Matrix.php
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,10 @@ private function _parseSubField($feedData, $subFieldHandle, $subFieldInfo): mixe

$subField = Hash::extract($this->field->getBlockTypeFields(), '{n}[handle=' . $subFieldHandle . ']')[0];

if (!$subField instanceof $subFieldClassHandle) {
$subFieldClassHandle = \craft\fields\Entries::class;
}

$class = Plugin::$plugin->fields->getRegisteredField($subFieldClassHandle);
$class->feedData = $feedData;
$class->fieldHandle = $subFieldHandle;
Expand Down
4 changes: 4 additions & 0 deletions src/fields/SuperTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,10 @@ private function _parseSubField($feedData, $subFieldHandle, $subFieldInfo): mixe

$subField = Hash::extract($this->field->getBlockTypeFields(), '{n}[handle=' . $subFieldHandle . ']')[0];

if (!$subField instanceof $subFieldClassHandle) {
$subFieldClassHandle = \craft\fields\Entries::class;
}

$class = Plugin::$plugin->fields->getRegisteredField($subFieldClassHandle);
$class->feedData = $feedData;
$class->fieldHandle = $subFieldHandle;
Expand Down
11 changes: 10 additions & 1 deletion src/services/Fields.php
Original file line number Diff line number Diff line change
Expand Up @@ -205,12 +205,21 @@ public function parseField($feed, $element, $feedData, $fieldHandle, $fieldInfo)

$fieldClassHandle = Hash::get($fieldInfo, 'field');

// if category groups or tag groups have been entrified, the fields for them could have been entrified too;
// get the field by handle, check if the type hasn't changed since the feed was last saved;
// if it hasn't changed - proceed as before
// if it has changed - assume that we've entrified and adjust the $fieldClassHandle
$field = Craft::$app->getFields()->getFieldByHandle($fieldHandle);
if (!$field instanceof $fieldClassHandle) {
$fieldClassHandle = \craft\fields\Entries::class;
}

// Find the class to deal with the attribute
$class = $this->getRegisteredField($fieldClassHandle);
$class->feedData = $feedData;
$class->fieldHandle = $fieldHandle;
$class->fieldInfo = $fieldInfo;
$class->field = Craft::$app->getFields()->getFieldByHandle($fieldHandle);
$class->field = $field;
$class->element = $element;
$class->feed = $feed;

Expand Down

0 comments on commit b439f86

Please sign in to comment.