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 »
  • 5.0 Saloon »
  • Custom annotations
Pages: [1]

Author Topic: Custom annotations  (Read 622 times)

totten

  • Administrator
  • Ask me questions
  • *****
  • Posts: 695
  • Karma: 64
Custom annotations
March 05, 2014, 01:46:34 pm
In the discussion of using Doctrine annotations with Civi, we've had some question of how we might add our own annotations. This commit provides an example:

https://github.com/totten/civicrm-core/commit/99bd914ffca7dab7002179967ea6b8f15be48917

For this commit, I'm experimenting with defining a REST interface backed by Doctrine entities. Each Doctrine entity needs a URL based on a URL-friendly name (a "slug" -- eg entity "WorldRegion" corresponds to path "/civicrm/rest/world-region", and the slug is "world-region"). The commit allows one to specify the slug with an extra annotation, "@CiviAPI\Entity", e.g.

Code: [Select]
<?php
use Doctrine\ORM\Mapping as ORM;
use 
Civi\API\Annotation as CiviAPI;

/**
 * @CiviAPI\Entity("UberWidget", slug="uber-widget")
 * @ORM\Table(name="civicrm_uber_widget")
 * @ORM\Entity
 */
class UberWidget {
}

Key things to note:

1. In Civi/API/Annotation/Entity.php, it defines the fields of the annotation.
2. In Civi\Core\Container::createAnnotationReader(), it registers the annotation with (roughly):

Code: [Select]
<?php
use Doctrine\Common\Annotations\AnnotationRegistry;
...
AnnotationRegistry::registerAutoloadNamespace('Civi', $civicrm_base_path);

3. In Civi/API/Registry.php, it builds and stores a cacheable mapping between slugs and class-names. This requires scanning all the entity classes for annotations. Note the calls to getAllClassNames() and getClassAnnotation().

There's more general discussion of creating annotations at http://docs.doctrine-project.org/projects/doctrine-common/en/latest/reference/annotations.html .

JoeMurray

  • Administrator
  • Ask me questions
  • *****
  • Posts: 578
  • Karma: 24
    • JMA Consulting
  • CiviCRM version: 4.4 and 4.5 (as of Nov 2014)
  • CMS version: Drupal, WordPress, Joomla
  • MySQL version: MySQL 5.5, 5.6, MariaDB 10.0 (as of Nov 2014)
Re: Custom annotations
May 18, 2014, 07:23:08 am
I like this direction alot.

As we expose more info via REST it might be useful to develop a more fine-grained permission model. I have the sense that option values for some option group slugs might benefit from more restrictive View/Edit permissions, while others might need to be exposed to unauthenticated calls.
Co-author of Using CiviCRM https://www.packtpub.com/using-civicrm/book

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion »
  • 5.0 Saloon »
  • Custom annotations

This forum was archived on 2017-11-26.