/**
  * {@inheritDoc}
  */
 public function getResourceId()
 {
     $this->__initializer__ && $this->__initializer__->__invoke($this, 'getResourceId', array());
     return parent::getResourceId();
 }
 /**
  * @return int
  */
 public function position()
 {
     return $this->templateProperty->getPosition();
 }
 /**
  * {@inheritDoc}
  */
 public function hydrate(Request $request, EntityInterface $entity, ErrorStore $errorStore)
 {
     $data = $request->getContent();
     $this->hydrateOwner($request, $entity);
     $this->hydrateResourceClass($request, $entity);
     if ($this->shouldHydrate($request, 'o:label')) {
         $entity->setLabel($request->getValue('o:label'));
     }
     if ($this->shouldHydrate($request, 'o:resource_template_property') && isset($data['o:resource_template_property']) && is_array($data['o:resource_template_property'])) {
         // Get a resource template property by property ID.
         $getResTemProp = function ($propertyId, $resTemProps) {
             foreach ($resTemProps as $resTemProp) {
                 if ($propertyId == $resTemProp->getProperty()->getId()) {
                     return $resTemProp;
                 }
             }
             return null;
         };
         $propertyAdapter = $this->getAdapter('properties');
         $resTemProps = $entity->getResourceTemplateProperties();
         $resTemPropsToRetain = [];
         $position = 1;
         foreach ($data['o:resource_template_property'] as $resTemPropData) {
             if (!isset($resTemPropData['o:property']['o:id'])) {
                 continue;
                 // skip when no property ID
             }
             $propertyId = $resTemPropData['o:property']['o:id'];
             $altLabel = null;
             if (isset($resTemPropData['o:alternate_label']) && '' !== trim($resTemPropData['o:alternate_label'])) {
                 $altLabel = $resTemPropData['o:alternate_label'];
             }
             $altComment = null;
             if (isset($resTemPropData['o:alternate_comment']) && '' !== trim($resTemPropData['o:alternate_comment'])) {
                 $altComment = $resTemPropData['o:alternate_comment'];
             }
             // Check whether a passed property is already assigned to this
             // resource template.
             $resTemProp = $getResTemProp($propertyId, $resTemProps);
             if ($resTemProp) {
                 // It is already assigned. Modify the existing entity.
                 $resTemProp->setAlternateLabel($altLabel);
                 $resTemProp->setAlternateComment($altComment);
             } else {
                 // It is not assigned. Add a new resource template property.
                 // No need to explicitly add it to the collection since it
                 // is added implicitly when setting the resource template.
                 $property = $propertyAdapter->findEntity($propertyId);
                 $resTemProp = new ResourceTemplateProperty();
                 $resTemProp->setResourceTemplate($entity);
                 $resTemProp->setProperty($property);
                 $resTemProp->setAlternateLabel($altLabel);
                 $resTemProp->setAlternateComment($altComment);
                 $entity->getResourceTemplateProperties()->add($resTemProp);
             }
             // Set the position of the property to its intrinsic order
             // within the passed array.
             $resTemProp->setPosition($position++);
             $resTemPropsToRetain[] = $resTemProp;
         }
         // Remove resource template properties that were not included in the
         // passed data.
         foreach ($resTemProps as $resTemPropId => $resTemProp) {
             if (!in_array($resTemProp, $resTemPropsToRetain)) {
                 $resTemProps->remove($resTemPropId);
             }
         }
     }
 }