Helper function for patch action.

@param $item

@throws \Sulu\Component\Rest\Exception\EntityNotFoundException

@return ContactTitle added or updated entity
359725
private function addAndUpdateTitles($item)
    {
        if (isset($item['id']) && !empty($item['id'])) {
            /* @var ContactTitle $title */
            $title = $this->getDoctrine()
                ->getRepository(self::$entityName)
                ->find($item['id']);

            if (null == $title) {
                throw new EntityNotFoundException(self::$entityName, $item['id']);
            } else {
                $title->setTitle($item['title']);
            }
        } else {
            $title = new ContactTitle();
            $title->setTitle($item['title']);
            $this->getDoctrine()->getManager()->persist($title);
        }

        return $title;
    }
677814
protected function get_item_title( array $item ) {

		if ( isset( $item['taxonomy'] ) ) {
			$tax = get_taxonomy( $item['taxonomy'] );
			if ( $tax ) {
				if ( ! empty( $tax->exclusive ) ) {
					return $tax->labels->singular_name;
				} else {
					return $tax->labels->name;
				}
			} else {
				return $item['taxonomy'];
			}
		} elseif ( isset( $item['post_field'] ) ) {
			return ucwords( trim( str_replace( [
				'post_',
				'_',
			], ' ', $item['post_field'] ) ) );
		} elseif ( isset( $item['meta_key'] ) ) {
			return ucwords( trim( str_replace( [
				'_',
				'-',
			], ' ', $item['meta_key'] ) ) );
		} elseif ( isset( $item['connection'] ) && isset( $item['field'] ) && isset( $item['value'] ) ) {

			$fallback = ucwords( trim( str_replace( [
				'_',
				'-',
			], ' ', $item['value'] ) ) );

			if ( ! function_exists( 'p2p_type' ) || ! $this->p2p_connection_exists( $item['connection'] ) ) {
				return $fallback;
			}

			$ctype = p2p_type( $item['connection'] );
			if ( ! $ctype ) {
				return $fallback;
			}

			if ( isset( $ctype->fields[ $item['field'] ]['values'][ $item['value'] ] ) ) {
				if ( '' === trim( $ctype->fields[ $item['field'] ]['values'][ $item['value'] ] ) ) {
					return $ctype->fields[ $item['field'] ]['title'];
				} else {
					return $ctype->fields[ $item['field'] ]['values'][ $item['value'] ];
				}
			}

			return $fallback;

		} elseif ( isset( $item['connection'] ) ) {
			if ( function_exists( 'p2p_type' ) && $this->p2p_connection_exists( $item['connection'] ) ) {
				$ctype = p2p_type( $item['connection'] );
				if ( $ctype ) {
					$other = ( 'from' === $ctype->direction_from_types( 'post', $this->cpt->post_type ) ) ? 'to' : 'from';
					return $ctype->side[ $other ]->get_title();
				}
			}
			return $item['connection'];
		}

	}
1219010
public function getAdminObjectTargetName($item)
    {
        if ($item->getTargetId()) {
            /** @var AbstractAdmin $admin */
            $admin = $this->getContainer()->get('sonata.admin.pool')->getAdminByClass($item->getClass());

            return $admin->getObject($item->getTargetId())->getName();
        }

        return '';
    }
1196562
private function addItem(Item $item)
    {
        $em = $this->getDoctrine()->getManager();
        $em->persist($item);
        $em->flush();

        return $this->redirect($this->generateUrl(
            'item_show',
            ['id' => $item->getId(), 'name' => $item->getUrlName()]
        ));
    }
1276176
public function addItem(\Interne\SeanceBundle\Entity\Item $item)
    {
        $this->items[] = $item;
        $item->setPosition($this->getNewPosition());
        $item->setMeeting($this);

        return $this;
    }
1036535
public function addItem($item = null, $action = null)
    {
        if (is_string($item)) {
            $item = ['Item', $item];
        } elseif (is_array($item)) {
            array_unshift($item, 'Item');
        } elseif (!$item) {
            $item = ['Item'];
        }

        $item = $this->add($item)->setElement('a');

        if (is_string($action) || is_array($action)) {
            $action = $this->url($action);
        }

        if (is_string($action)) {
            $item->setAttr('href', $action);
        }

        if ($action instanceof jsExpressionable) {
            $item->js('click', $action);
        }

        return $item;
    }
331284
private function importItem(array $item)
    {
        if (!$this->converter->supports($item)) {
            throw new ConverterNotFoundException($item);
        }

        $entity = $this->converter->convert($item);
        $this->writer->write($entity);

        return $entity;
    }
1372052
private function hydrate($item)
    {
        if ($item === null) {
            return null;
        }

        return $this->uow->getOrCreateDocument(
            $this->class,
            $item,
            null,
            $this->readOnly,
            $this->refresh
        );
    }
415850
public function addItem(Item $item)
    {
        if (!$this->items->contains($item)) {
            $this->items->add($item);
            $item->setStudio($this);
        }

        return $this;
    }
339208
public function getUpdateUrl($entity)
    {
        if(!$this->getEntityService()->isEntityInstance($entity)) {
            throw new NotEntityException();
        }
        
        return $this->url()->fromRoute($this->getEvent()->getRouteMatch()->getMatchedRouteName(), array(
            'action' => 'update', 'id' => $entity->getId()
        ));
    }
1353393
public function addItem(Item $item)
    {
        if (!$this->items->contains($item)) {
            $this->items->add($item);
            $item->setType($this);
        }

        return $this;
    }
1256520
public function fillAction(Item $item)
    {
        // do fill
        $this->get('anime_db.item_folder_filler.filler_folder')->fillFolder($item);

        return $this->render('AnimeDbItemFolderFillerBundle:Filler:fill.html.twig', [
            'item' => $item
        ]);
    }
459122
private function processForm(Item $item) {

        $created = ($item && null === $item->getId());
        $statusCode = ($created)? Response::HTTP_CREATED : Response::HTTP_NO_CONTENT;
        $method = ($created) ? "POST" : "PUT";

        $form = $this->createForm(new ItemType(), $item, array('method' => $method));
        $form->handleRequest($this->getRequest());

        $view;
        if ($form->isValid()) {
            $em = $this->getDoctrine()->getManager();
            $em->persist($item);
            $em->flush();

            $view = $this->view()->setStatusCode($statusCode);

            // HTTP Convention : return HTTP 201 Created + Location of created resource
            if ($created) {
                $view->setLocation(
                    $this->generateUrl('get_item', ['id' => $item->getId()])
                );
            }
        } else {
            $view = $this->view($form, Response::HTTP_BAD_REQUEST);
        }

        return $this->handleView($view);
    }
1200196
public function patchAction(Request $request, $id)
    {
        $locale = $this->getProductLocaleManager()->retrieveLocale($this->getUser(), $request->get('locale'));

        try {
            $product = $this->getManager()->partialUpdate(
                $request->request->all(),
                $locale,
                $this->getUser()->getId(),
                $id
            );

            $this->getEntityManager()->flush();

            $view = $this->view($product, 200);
        } catch (ProductNotFoundException $exc) {
            $exception = new EntityNotFoundException($exc->getEntityName(), $exc->getId());
            $view = $this->view($exception->toArray(), 404);
        }

        return $this->handleView($view);
    }
846718
private function entityToReference(&$item, $key) {
    if ($this->isASleepingReference) {
      $this->referenceWake();
    }
    if ((is_a($item, '\Nymph\Entity') || is_a($item, '\SciActive\HookOverride'))
        && isset($item->guid) && is_callable([$item, 'toReference'])) {
      // This is an entity, so we should put it in the entity cache.
      if (!isset($this->entityCache["referenceGuid__{$item->guid}"])) {
        $this->entityCache["referenceGuid__{$item->guid}"] = clone $item;
      }
      // Make a reference to the entity (its GUID and the class the entity was
      // loaded as).
      $item = $item->toReference();
    }
  }
1268764
public function addItem(Item $item)
    {
        $this->items->put($item->getName(), $item);

        return $this;
    }
1231860
protected function updateItem(\oat\taoQtiItem\model\qti\Item $item, $itemFile)
    {
        $changed = false;
        $responses = $item->getResponses();

        foreach ($responses as $response) {

            $responseIdentifier = $response->attr('identifier');
            $rules              = $response->getFeedbackRules();

            foreach ($rules as $rule) {
                $modalFeedbacks = array();
                if ($rule->getFeedbackThen()) {
                    $modalFeedbacks[] = $rule->getFeedbackThen();
                }
                if ($rule->getFeedbackElse()) {
                    $modalFeedbacks[] = $rule->getFeedbackElse();
                }
                foreach ($modalFeedbacks as $modalFeedback) {
                    $feedbackXml = simplexml_load_string($modalFeedback->toQti());
                    if ($feedbackXml->div[0] && $feedbackXml->div[0]['class'] && preg_match('/^x-tao-wrapper/',
                            $feedbackXml->div[0]['class'])) {
                        //the item body has not already been wrapped by the new wrapper <div class="x-tao-wrapper w-tao-relatedOutcome-{{response.identifier}}">
                        continue;
                    }
                    $message = $modalFeedback->getBody()->getBody();
                    $modalFeedback->getBody()->edit('<div class="x-tao-wrapper x-tao-relatedOutcome-'.$responseIdentifier.'">'.$message.'</div>',
                        true);
                    $changed = true;
                }
            }
        }

        return $changed;
    }