Skip to content

Instantly share code, notes, and snippets.

@undertext
Last active April 10, 2019 09:11
Show Gist options
  • Save undertext/91ad6d3e7297047a778d17d0b7d6a4ce to your computer and use it in GitHub Desktop.
Save undertext/91ad6d3e7297047a778d17d0b7d6a4ce to your computer and use it in GitHub Desktop.
<?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