Commit a0a1b36c authored by jaapjansma's avatar jaapjansma
Browse files

Added action add tag to contact

parent 5b80509c
......@@ -3,6 +3,7 @@ Version 1.5
* Added action Get Relationship By Contact ID
* Added action Get State/Province ID by name
* Added action Add Tag to Contact
* Fixed issue with the Get Relationship action
Version 1.4
......
<?php
/**
* @author Jaap Jansma <jaap.jansma@civicoop.org>
* @license AGPL-3.0
*/
namespace Civi\ActionProvider\Action\Tag;
use Civi\ActionProvider\Action\AbstractAction;
use Civi\ActionProvider\Parameter\ParameterBagInterface;
use Civi\ActionProvider\Parameter\Specification;
use Civi\ActionProvider\Parameter\SpecificationBag;
use Civi\FormProcessor\API\Exception;
use CRM_ActionProvider_ExtensionUtil as E;
class AddTagToContact extends AbstractAction {
protected function doAction(ParameterBagInterface $parameters, ParameterBagInterface $output) {
$tag = $parameters->getParameter('tag');
$tag_id = false;
try {
$tag_id = civicrm_api3('Tag', 'getvalue', ['return' => 'id', 'name' => $tag, 'used_for' => 'Contacts']);
} catch (\Exception $e) {
$result = civicrm_api3('Tag', 'create', ['name' => $tag, 'used_for' => 'Contacts']);
$tag_id = $result['id'];
}
civicrm_api3('EntityTag', 'create', [
'tag_id' => $tag_id,
'entity_id' => $parameters->getParameter('contact_id'),
'entity_table' => 'civicrm_contact',
]);
}
public function getConfigurationSpecification() {
return new SpecificationBag();
}
public function getParameterSpecification() {
return new SpecificationBag([
new Specification('contact_id', 'Integer', E::ts('Contact ID'), true),
new Specification('tag', 'String', E::ts('Tag'), true)
]);
}
}
......@@ -288,6 +288,10 @@ class Provider {
AbstractAction::DATA_MANIPULATION_TAG,
AbstractAction::SINGLE_CONTACT_ACTION_TAG
));
$this->addActionWithoutFiltering('AddTagToContact', '\Civi\ActionProvider\Action\Tag\AddTagToContact', E::ts('Add tag to contact'), array(
AbstractAction::DATA_MANIPULATION_TAG,
AbstractAction::SINGLE_CONTACT_ACTION_TAG
));
$conditions = array(
new \Civi\ActionProvider\Condition\ParameterIsEmpty(),
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment