/** * {@inheritdoc} */ public function getVirtualFields($className) { if ($this->taggableHelper->isTaggable($className)) { return [self::TAG_FIELD]; } return []; }
/** * {@inheritdoc} */ public function process($entity) { if (!$this->taggableHelper->isTaggable($entity)) { throw new \LogicException('Target entity should be taggable.'); } return parent::process($entity); }
/** * @param mixed $context * @param string $path * * @return object */ protected function getTaggable($context, $path) { $object = $this->getObject($context, $path); if (!$this->taggableHelper->isTaggable($object)) { throw new LogicException(sprintf('Object in path "%s" in "copy_tagging" action should be taggable.', $path)); } return $object; }
public function testNotTaggable() { $this->helper->expects($this->once())->method('isTaggable')->willReturn(false); $this->entityMetadata = $this->getMockBuilder('Oro\\Bundle\\EntityMergeBundle\\Metadata\\EntityMetadata')->setMethods(['getClassName', 'addFieldMetadata'])->disableOriginalConstructor()->getMock(); $this->entityMetadata->expects($this->any())->method('getClassName')->will($this->returnValue(get_class($this->createNotTaggableEntity()))); $this->entityMetadata->expects($this->never())->method('addFieldMetadata'); $event = new EntityMetadataEvent($this->entityMetadata); $this->listener->onBuildMetadata($event); }
/** * @param FormEvent $event */ public function preSet(FormEvent $event) { $entity = $event->getForm()->getParent()->getData(); if (!$this->taggableHelper->isTaggable($entity)) { return; } $this->tagManager->loadTagging($entity); $tags = $this->tagManager->getPreparedArray($entity, null, $this->organization); $event->setData($tags); }
/** * @param LifecycleEventArgs $args */ public function preRemove(LifecycleEventArgs $args) { $entity = $args->getEntity(); if ($this->taggableHelper->isTaggable($entity)) { if (null === $this->tagManager && $this->container) { $this->tagManager = $this->container->get('oro_tag.tag.manager'); } $this->tagManager->deleteTagging($entity, []); } }
/** * Add tag field as last field in first data block * * @param BeforeViewRenderEvent $event */ public function addTagField(BeforeViewRenderEvent $event) { $entity = $event->getEntity(); if ($entity && $this->taggableHelper->isTaggable($entity)) { $environment = $event->getTwigEnvironment(); $data = $event->getData(); $tagField = $environment->render('OroTagBundle::tagField.html.twig', ['entity' => $entity]); if (!empty($data['dataBlocks'])) { if (isset($data['dataBlocks'][0]['subblocks'])) { array_push($data['dataBlocks'][0]['subblocks'][0]['data'], $tagField); } } $event->setData($data); } }
/** * @dataProvider isTaggableDataProvider * * @param object $object * @param bool $expected * @param bool|false $needSetConfig * @param bool|false $hasConfig * @param bool|false $isEnableGridFilter */ public function testIsEnableGridFilter($object, $expected, $needSetConfig = false, $hasConfig = false, $isEnableGridFilter = false) { if ($needSetConfig) { $this->setConfigProvider($object, $hasConfig, $isEnableGridFilter); } $this->assertEquals($expected, $this->helper->isEnableGridColumn($object)); }
/** * @param $options * * @return bool */ protected function isImplementsTaggable($options) { /** @var EntityConfigId $configId */ $configId = $options['config_id']; $className = $configId->getClassName(); if (!empty($className)) { return TaggableHelper::isImplementsTaggable($className); } return false; }
/** * @param object $entity * * @return bool */ public function isTaggable($entity) { return $this->taggableHelper->isTaggable($entity); }
/** * {@inheritdoc} */ public function getVirtualRelations($className) { return $this->taggableHelper->isTaggable($className) ? [self::RELATION_NAME => $this->getRelationDefinition($className)] : []; }
/** * Fetch tags for the given entity * * @param object $entity entity * @param User $owner * @param bool $all * @param Organization $organization * * @return Collection */ protected function fetchTags($entity, $owner, $all = false, Organization $organization = null) { $repository = $this->getTagsRepository(); $usedOrganization = $organization ?: $this->getOrganization(); $elements = $repository->getTags(ClassUtils::getClass($entity), TaggableHelper::getEntityId($entity), $owner, $all, $usedOrganization); return new ArrayCollection($elements); }
protected function setHelperExpectation($isTaggable, $entityIdentifierFieldName = 'id') { $this->taggableHelper->expects($this->any())->method('isTaggable')->willReturn($isTaggable); $this->doctrineHelper->expects($this->any())->method('getSingleEntityIdentifierFieldName')->willReturn($entityIdentifierFieldName); }
/** * Gets definition for tag column filter. * * @param DatagridConfiguration $config * * @return array */ protected function getColumnFilterDefinition(DatagridConfiguration $config) { $className = $this->getEntityClassName($config); $from = $config->offsetGetByPath(self::GRID_FROM_PATH); return ['type' => 'tag', 'data_name' => $from[0]['alias'] . '.id', 'label' => 'oro.tag.entity_plural_label', 'enabled' => $this->taggableHelper->isEnableGridFilter($className), 'options' => ['field_options' => ['entity_class' => $className]]]; }
protected function setHelperExpectation($isTaggable) { $this->helper->expects($this->once())->method('isTaggable')->willReturn($isTaggable); }
/** * {@inheritdoc} */ public function supports($entity, FieldMetadata $metadata) { return $this->taggableHelper->isTaggable($entity) && $metadata->getSourceClassName() === 'Oro\\Bundle\\TagBundle\\Entity\\Tag'; }
/** * Gets definition for tag column filter. * * @param DatagridConfiguration $config * * @return array */ protected function getColumnFilterDefinition(DatagridConfiguration $config) { $className = $this->getEntity($config); $alias = $this->gridConfigurationHelper->getEntityRootAlias($config); return ['type' => 'tag', 'data_name' => sprintf('%s.%s', $alias, 'id'), 'label' => 'oro.tag.entity_plural_label', 'enabled' => $this->taggableHelper->isEnableGridFilter($className), 'options' => ['field_options' => ['entity_class' => $className]]]; }
/** * Sets the resource * * @param Taggable $resource Resource to set */ public function setResource(Taggable $resource) { $this->entityName = ClassUtils::getClass($resource); $this->recordId = TaggableHelper::getEntityId($resource); }
/** * Returns tags with taggings loaded by resource * * @param object $resource * @param int|null $createdBy * @param bool $all * @param Organization $organization * * @return array * * @deprecated Use {@see getTags} instead */ public function getTagging($resource, $createdBy = null, $all = false, Organization $organization = null) { $recordId = TaggableHelper::getEntityId($resource); return $this->getTags(ClassUtils::getClass($resource), $recordId, $createdBy, $all, $organization); }
/** * Return true if given class name is taggable * * @param $className * * @return bool */ protected function isTaggable($className) { return $this->taggableHelper->isTaggable($className); }
/** * @param EntityMetadata $entityMetadata * * @return bool */ private function isTaggable(EntityMetadata $entityMetadata) { $className = $entityMetadata->getClassName(); return $this->taggableHelper->isTaggable($className); }