Doctrine\ODM\PHPCR\UnitOfWork::bindTranslation PHP Method

bindTranslation() public method

This method will update the field mapped to Locale if it does not match the $locale argument.
public bindTranslation ( object $document, string $locale )
$document object the document to persist a translation of
$locale string the locale this document currently has
    public function bindTranslation($document, $locale)
    {
        $state = $this->getDocumentState($document);
        if ($state !== self::STATE_MANAGED) {
            throw new InvalidArgumentException('Document has to be managed to be able to bind a translation ' . self::objToStr($document, $this->dm));
        }
        $class = $this->dm->getClassMetadata(get_class($document));
        if (!$this->isDocumentTranslatable($class)) {
            throw new PHPCRException('This document is not translatable, do not use bindTranslation: ' . self::objToStr($document, $this->dm));
        }
        if ($this->getCurrentLocale($document) != $locale && false !== array_search($locale, $this->getLocalesFor($document))) {
            throw new RuntimeException(sprintf('Translation "%s" already exists for "%s". First load this translation if you want to change it, or remove the existing translation.', $locale, self::objToStr($document, $this->dm)));
        }
        $this->doBindTranslation($document, $locale, $class);
    }

Usage Example

Beispiel #1
0
 /**
  * {@inheritDoc}
  */
 public function bindTranslation($document, $locale)
 {
     if (!is_object($document)) {
         throw new InvalidArgumentException('Parameter $document needs to be an object, ' . gettype($document) . ' given');
     }
     $this->errorIfClosed();
     $this->unitOfWork->bindTranslation($document, $locale);
 }
All Usage Examples Of Doctrine\ODM\PHPCR\UnitOfWork::bindTranslation
UnitOfWork