CiviCRM Community Forums (archive)

*

News:

Have a question about CiviCRM?
Get it answered quickly at the new
CiviCRM Stack Exchange Q+A site

This forum was archived on 25 November 2017. Learn more.
How to get involved.
What to do if you think you've found a bug.



  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion »
  • APIs and Hooks (Moderator: Donald Lobo) »
  • Trouble updating a contact's entity tags
Pages: [1]

Author Topic: Trouble updating a contact's entity tags  (Read 636 times)

amcnaughton

  • I’m new here
  • *
  • Posts: 1
  • Karma: 0
  • CiviCRM version: 4.5.6
  • CMS version: Joomla
  • MySQL version: 14.14
  • PHP version: 5.4
Trouble updating a contact's entity tags
June 05, 2015, 09:01:14 am
I'm displaying a contacts entity tags in my app, allowing the user to select/deselect tags, and attempting to update the set of entity tags when the contact is saved.

Here's my code to get the tags (it works fine).

    public function getEntityTags($contactId)
    {
        $result = civicrm_api3('EntityTag', 'get', array(
            'entity_id' => $contactId,
            'options' => array('limit' => 100)
        ));

        if (empty($result['values']))
            return [];
        else {
            foreach ($result['values'] as $key => $value)
                $tags[$key] = $value['tag_id'];
            return $tags;
        }
    }

I've tried multiple ways to add / delete the contacts tags, but have not succeeded. One issue is that the above api call only returns the tag_id, not the id of the row holding the entity tag row.

The Entity Tag delete api, which I need if the user deselects a previously selected tag requires the actual row id as such:

    $result = civicrm_api3('EntityTag', 'delete', array(
      'id' => "SomeId",
    ));

I thought of using the replace action but can't find any documentation on how to make it work. Here's what I would like to do.

            $result = civicrm_api3('EntityTag', 'replace', array(
                'sequential' => 1,
                'entity_id' => $contactId,
                'tag_id' => $newTags,
            ));

In the above code (which fails with "Mandatory key(s) missing from params array: values") $newTags is an array of tags the contact should have. I was hoping "replace" would update the complete set of entity tags with the new set.

Please help as I'm currently at a dead end.

JonGold

  • Ask me questions
  • ****
  • Posts: 638
  • Karma: 81
    • Palante Technology
  • CiviCRM version: 4.1 to the latest
  • CMS version: Drupal 6-7, Wordpress 4.0+
  • PHP version: PHP 5.3-5.5
Re: Trouble updating a contact's entity tags
June 05, 2015, 12:13:05 pm
This is an excellent question!  However, at this point questions like this should go to http://civicrm.stackexchange.com.

I took a quick look though - and I think you've found a bug.  If you do a EntityTag.get without specifying an argument, it returns all the fields.  When you specify an entity_id, it just returns the tag_id.  I'd definitely post this on StackExchange - and probably on issues.civicrm.org as well.
Sign up to StackExchange and get free expert CiviCRM advice: https://civicrm.org/blogs/colemanw/get-exclusive-access-free-expert-help

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion »
  • APIs and Hooks (Moderator: Donald Lobo) »
  • Trouble updating a contact's entity tags

This forum was archived on 2017-11-26.