Exemplo n.º 1
0
 /**
  * @param array $params
  *
  * @return ChangeOpAliases
  */
 private function getChangeOps(array $params)
 {
     $changeOps = array();
     $language = $params['language'];
     // Set the list of aliases to a user given one OR add/ remove certain entries
     if (isset($params['set'])) {
         $changeOps[] = $this->termChangeOpFactory->newSetAliasesOp($language, $this->normalizeAliases($params['set']));
     } else {
         // FIXME: if we have ADD and REMOVE operations in the same call,
         // we will also have two ChangeOps updating the same edit summary.
         // This will cause the edit summary to be overwritten by the last ChangeOp beeing applied.
         if (!empty($params['add'])) {
             $changeOps[] = $this->termChangeOpFactory->newAddAliasesOp($language, $this->normalizeAliases($params['add']));
         }
         if (!empty($params['remove'])) {
             $changeOps[] = $this->termChangeOpFactory->newRemoveAliasesOp($language, $this->normalizeAliases($params['remove']));
         }
     }
     return $changeOps;
 }
 /**
  * @param array[] $indexedAliases
  *
  * @return ChangeOp[]
  */
 private function getIndexedAliasesChangeOps(array $indexedAliases)
 {
     $aliasesChangeOps = array();
     foreach ($indexedAliases as $langCode => $args) {
         $aliasesToSet = array();
         $language = '';
         foreach ($args as $arg) {
             $this->validateMultilangArgs($arg, $langCode);
             $alias = array($this->stringNormalizer->trimToNFC($arg['value']));
             $language = $arg['language'];
             if (array_key_exists('remove', $arg)) {
                 $aliasesChangeOps[] = $this->termChangeOpFactory->newRemoveAliasesOp($language, $alias);
             } elseif (array_key_exists('add', $arg)) {
                 $aliasesChangeOps[] = $this->termChangeOpFactory->newAddAliasesOp($language, $alias);
             } else {
                 $aliasesToSet[] = $alias[0];
             }
         }
         if ($aliasesToSet !== array()) {
             $aliasesChangeOps[] = $this->termChangeOpFactory->newSetAliasesOp($language, $aliasesToSet);
         }
     }
     return $aliasesChangeOps;
 }