diff --git a/src/Plugin/RulesAction/Tweet.php b/src/Plugin/RulesAction/Tweet.php index 9133650..6a30669 100644 --- a/src/Plugin/RulesAction/Tweet.php +++ b/src/Plugin/RulesAction/Tweet.php @@ -94,6 +94,7 @@ class Tweet extends RulesActionBase implements ContainerFactoryPluginInterface { $this->twitterPost = $twitter_post; $this->twitterEntity = $entity_manager->getStorage('social_post_twitter_user'); $this->currentUser = $current_user; + $this->tokenManager = $token_manager; } /** @@ -103,6 +104,8 @@ class Tweet extends RulesActionBase implements ContainerFactoryPluginInterface { * The tweet text. */ protected function doExecute($status) { + $status = $this->tokenManager->formatStatus($status); + $accounts = $this->getTwitterAccountsByUserId($this->currentUser->id()); /* @var \Drupal\social_post_twitter\Entity\TwitterUserInterface $account */ foreach ($accounts as $account) { diff --git a/src/TwitterPostTokenManager.php b/src/TwitterPostTokenManager.php deleted file mode 100644 index a30cca7..0000000 --- a/src/TwitterPostTokenManager.php +++ /dev/null @@ -1,133 +0,0 @@ -token = $token; - $this->entityManager = $entity_manager; - $this->routeMatch = $route_match; - $this->currentUser = $current_user; - $this->entityQuery = $entity_query; - } - - /** - * Formats the status replacing the tokens. - * - * @param string $status - * The raw status value. - * - * @return string - * The processed status value. - */ - public function formatStatus($status) { - $data = $this->getDataArray($status); - - return $this->token->replace($status, $data); - } - - /** - * Returns the data array for token replacing. - * - * @param string $text - * The string to process. - * - * @return array - * The data array with entities that replace the tokens. - * - * @TODO cover all the possible tokens. - */ - protected function getDataArray($text) { - $data = []; - - $tokens = $this->token->scan($text); - - foreach (array_keys($tokens) as $token) { - switch ($token) { - case 'node': - $node = $this->routeMatch->getParameter('node'); - if ($node) { - $data['node'] = $node; - } else { // This approach is used when a new node is created. - $nid = $this->entityQuery->getAggregate('node', 'AND') - ->aggregate('nid', 'MAX') - ->execute()[0]['nid_max']; - - $data['node'] = $this->entityManager->getStorage('node')->load($nid); - } - break; - - case 'user': - $data['user'] = $this->entityManager->getStorage('user')->load($this->currentUser->id()); - break; - - } - } - - return $data; - } - -}