Skip to content

Commit

Permalink
Fix element validation issue when saving
Browse files Browse the repository at this point in the history
Fixes #478
  • Loading branch information
Tam committed Apr 29, 2024
1 parent 5994e31 commit 3002b5a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
## 5.0.0 - 2024-03-01
## 5.0.0-rc2 - 2024-04-29
### Fixed
- Fix element validation issue when saving (Fixes #478)

## 5.0.0-rc1 - 2024-03-01
### Changed
- Add support for Craft 5

Expand Down
14 changes: 9 additions & 5 deletions src/models/data/SeoData.php
Original file line number Diff line number Diff line change
Expand Up @@ -452,20 +452,24 @@ private function _getVariables ()

if ($this->_element !== null)
{
foreach (array_keys($this->_element->fields()) as $name)
foreach ($this->_element->getFieldLayout()->getCustomFields() as $field) {
$name = $field->handle;

if ($name !== $this->_handle)
$variables[$name] = $this->_element->$name ?? null;
}

if (!array_key_exists('type', $variables) && $this->_element->hasMethod('getType'))
$variables['type'] = $this->_element->getType();

if (!array_key_exists('section', $variables) && $this->_element->hasMethod('getSection'))
$variables['section'] = $this->_element->getSection();

$variables = array_merge(
$variables,
$this->_element->toArray($this->_element->extraFields(), [], false)
);
if (!array_key_exists('site', $variables) && $this->_element->hasMethod('getSite'))
$variables['site'] = $this->_element->getSite();

if (!array_key_exists('author', $variables) && $this->_element->hasMethod('getAuthor'))
$variables['author'] = $this->_element->getAuthor();
}

return $variables;
Expand Down

0 comments on commit 3002b5a

Please sign in to comment.