/**
  * Given an attribute and an array of Values, perform database and relation
  * stuff
  *
  * @param AttributeInterface $attribute Attribute
  * @param array              $values    Values
  *
  * @return $this Self object
  */
 protected function evaluateAttributeValues(AttributeInterface $attribute, array $values = [])
 {
     $actualValues = [];
     $values = array_filter($values, function ($value) {
         return !empty($value);
     });
     /**
      * We remove all deleted values
      */
     $attribute->setValues($attribute->getValues()->filter(function (ValueInterface $value) use($attribute, $values, &$actualValues) {
         $found = false;
         if (in_array($value->getValue(), $values)) {
             $actualValues[] = $value->getValue();
             $found = true;
         } else {
             $attribute->removeValue($value);
         }
         return $found;
     }));
     $newValues = array_diff($values, $actualValues);
     foreach ($newValues as $newValue) {
         $value = $this->get('elcodi.factory.attribute_value')->create()->setValue($newValue)->setAttribute($attribute);
         $attribute->addValue($value);
     }
     return $this;
 }
 /**
  * New element component action
  *
  * As a component, this action should not return all the html macro, but
  * only the specific component
  *
  * @param FormView           $formView  Form view
  * @param AttributeInterface $attribute Attribute
  *
  * @return array Result
  *
  * @Route(
  *      path = "/{id}/component",
  *      name = "admin_attribute_edit_component",
  *      requirements = {
  *          "id" = "\d+",
  *      },
  *      methods = {"GET", "POST"}
  * )
  * @Route(
  *      path = "/new/component",
  *      name = "admin_attribute_new_component",
  *      methods = {"GET"}
  * )
  * @Template("AdminAttributeBundle:Attribute:editComponent.html.twig")
  *
  * @EntityAnnotation(
  *      class = {
  *          "factory" = "elcodi.factory.attribute",
  *          "method" = "create",
  *          "static" = false
  *      },
  *      name = "attribute",
  *      mapping = {
  *          "id" = "~id~"
  *      },
  *      mappingFallback = true,
  * )
  * @FormAnnotation(
  *      class = "elcodi_admin_attribute_form_type_attribute",
  *      name  = "formView",
  *      entity = "attribute",
  *      handleRequest = true,
  *      validate = "isValid"
  * )
  */
 public function editComponentAction(FormView $formView, AttributeInterface $attribute)
 {
     $allAvailableValues = $this->get('elcodi.repository.attribute_value')->findAll();
     $attributeValues = $attribute->getValues()->toArray();
     return ['attribute' => $attribute, 'form' => $formView, 'attributeValues' => $this->getValuesSplittedByComma($attributeValues), 'allValues' => $this->getValuesSplittedByComma($allAvailableValues)];
 }