Sonata\ProductBundle\Block\VariationsFormBlockService::execute PHP Метод

execute() публичный Метод

public execute ( Sonata\BlockBundle\Block\BlockContextInterface $blockContext, Response $response = null )
$blockContext Sonata\BlockBundle\Block\BlockContextInterface
$response Symfony\Component\HttpFoundation\Response
    public function execute(BlockContextInterface $blockContext, Response $response = null)
    {
        $product = $blockContext->getSetting('product');
        if (null === $product) {
            return $this->renderResponse($blockContext->getTemplate(), array('context' => $blockContext, 'settings' => $blockContext->getSettings(), 'block' => $blockContext->getBlock(), 'choices' => array(), 'form' => null), $response);
        }
        $fields = $blockContext->getSetting('variations_properties');
        $choices = $this->pool->getProvider($product)->getVariationsChoices($product, $fields);
        $accessor = PropertyAccess::createPropertyAccessor();
        $currentValues = array();
        foreach ($choices as $field => $values) {
            $currentValues[$field] = array_search($accessor->getValue($product, $field), $values);
        }
        $form = $this->formFactory->createBuilder('sonata_product_variation_choices', $currentValues, array('field_options' => $blockContext->getSetting('form_field_options'), 'product' => $product, 'fields' => $fields))->getForm();
        $params = array('context' => $blockContext, 'settings' => $blockContext->getSettings(), 'block' => $blockContext->getBlock(), 'choices' => $choices, 'form' => $form->createView());
        return $this->renderResponse($blockContext->getTemplate(), $params, $response);
    }