public static function Generic::rewriteFieldLookup in Drupal 7 to 8/9 Module Upgrader 8
Rewrites a Drupal 7 field lookup like so:
$node->body[LANGUAGE_NONE][0]['value'] --> $node->body[0]->value $node->body['fr'][0]['value'] --> $node->getTranslation('fr')->body[0]->value
Parameters
\Pharborist\ArrayLookupNode $node: The original field lookup.
Return value
\Pharborist\ExpressionNode
2 calls to Generic::rewriteFieldLookup()
- Generic::rewrite in src/
Plugin/ DMU/ Rewriter/ Generic.php - Parametrically rewrites the function containing the given parameter.
- GenericTest::testRewriteFieldLookup in tests/
src/ Unit/ Plugin/ DMU/ Rewriter/ GenericTest.php
File
- src/
Plugin/ DMU/ Rewriter/ Generic.php, line 254
Class
- Generic
- Plugin annotation @Rewriter( id = "_rewriter", deriver = "\Drupal\drupalmoduleupgrader\Plugin\DMU\Rewriter\GenericDeriver" )
Namespace
Drupal\drupalmoduleupgrader\Plugin\DMU\RewriterCode
public static function rewriteFieldLookup(ArrayLookupNode $node) {
$keys = $node
->getKeys();
/** @var \Pharborist\Objects\ObjectPropertyNode $root */
$root = $node
->getRootArray();
$expr = $root
->getObject()
->getText();
if (self::isTranslation($keys[0])) {
$expr .= '->getTranslation(' . $keys[0] . ')';
}
$expr .= '->' . $root
->getPropertyName() . '[' . $keys[1] . ']';
/** @var \Pharborist\Types\StringNode|\Pharborist\Node $column */
foreach (array_slice($keys, 2) as $column) {
$expr .= '->';
$expr .= $column instanceof StringNode ? $column
->toValue() : $column
->getText();
}
return Parser::parseExpression($expr);
}