New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
EZP-28118: Error in RelationConverter on content after editing class in legacy #2115
Conversation
…on field definition in legacy
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Make sense 👍
if ( | ||
($selectionType = $dom->getElementsByTagName('selection_type')) && | ||
$selectionType->item(0)->hasAttribute('value') | ||
) { | ||
$fieldSettings['selectionMethod'] = (int)$selectionType->item(0)->getAttribute('value'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Quick test showed me that getElementsByTagName
never returns an empty value. It's always \DOMNodeList
. It has property length
. If length = 0
, then $selectionType->item(0)
will return null
and calling hasAttribute
will throw an exception.
So rather:
if (($selectionTypeFirstItem = $dom->getElementsByTagName('selection_type')->item(0)) && $selectionTypeFirstItem->hasAttribute('value'))
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, so DomList never evaluates to empty here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. Consider the following example (just re-pasting from elsewhere to keep discussion here consistent):
$xml = <<< XML
<?xml version="1.0" encoding="utf-8"?>
<para></para>
XML;
$dom = new DOMDocument;
$dom->loadXML($xml);
if (($elements = $dom->getElementsByTagName('non_existent_tag'))) {
var_dump($elements->item(0));
}
will output NULL
.
if ( | ||
($selectionType = $dom->getElementsByTagName('selection_type')) && | ||
$selectionType->item(0)->hasAttribute('value') | ||
) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same remark as above
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good :)
Todo: