Last active
April 10, 2019 09:11
-
-
Save undertext/91ad6d3e7297047a778d17d0b7d6a4ce to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function urban_module_node_presave(NodeInterface $node) { | |
if ($node->bundle() == 'urban_definition') { | |
/** @var \Drupal\urban_module\Service\UrbanDictionaryService $ubService */ | |
$ubService = \Drupal::service('urban_module.service'); | |
$definition = $ubService->getDefinition($node->getTitle()); | |
if (!empty($definition)) { | |
$node->title->value = $definition->getTerm(); | |
$node->field_definition->value = $definition->getDefinition(); | |
$node->field_example->value = $definition->getExample(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment