Get prepared view parameters

@param \Wanjee\Shuwee\AdminBundle\Datagrid\Field\DatagridFieldInterface $field
@param mixed $entity Instance of a model entity

@return mixed
172658
public function getBlockVariables($field, $entity)
    {
        $defaults = parent::getBlockVariables($field, $entity);

        $base_path = $field->getOption('base_path', 'uploads');
        $image = $defaults['value'];

        $value = null;
        if (!empty($image)) {
            $value = $base_path . '/' . $image;
        }

        return [
            'value' => $value,
        ] + $defaults;
    }
1257424
private function generateEntityAction(ModelInterface $entity) {
        session_write_close();
        $show = new Show($entity);
        $showCriteria = new ShowCriteria($this->request);
        return $show->generate($showCriteria->getField());
    }
1349989
protected function generateHasMethod(Entity $entity, FieldDescriptorProto $field)
    {
        $fieldName  = $field->getName();
        $methodName = $this->getAccessorName('has', $field);
        $method     = MethodGenerator::fromArray([
            'name'       => $methodName,
            'body'       => 'return $this->' . $fieldName . ' !== null;',
            'docblock'   => [
                'shortDescription' => "Check if '$fieldName' has a value",
                'tags'             => [
                    [
                        'name'        => 'return',
                        'description' => 'bool',
                    ]
                ]
            ]
        ]);

        return $method;
    }
1255123
public function transform(FieldTypeInterface $field)
    {
        return [
            'attributes' => $field->getAttributes(),
            'basename' => $field->getBaseName(),
            'component' => $field->getComponent(),
            'data_type' => $field->getOption('data_type', ''),
            'default' => $field->getOption('data', ''),
            'name' => $field->getName(),
            'options' => $this->getOptions($field),
            'label' => [
                'inner' => $field->getOption('label'),
                'attributes' => $field->getOption('label_attr', [])
            ],
            'theme' => $field->getTheme(),
            'type' => $field->getType(),
            'validation' => [
                'errors' => $field->getOption('errors', true),
                'messages' => $field->errors()->toArray(),
                'placeholder' => $field->getOption('placeholder'),
                'rules' => $field->getOption('rules', '')
            ],
            'value' => 'checkbox' === $field->getType() ? $field->getRawValue() : $field->getValue(''),
        ];
    }
498162
protected function generateExtensionField(Entity $entity, FieldDescriptorProto $field)
    {
        $name     = $field->getName();
        $number   = $field->getNumber();
        $docBlock = $this->getDocBlockType($field);
        $type     = $this->getFieldTypeName($field);
        $label    = $this->getFieldLabelName($field);
        $property = PropertyGenerator::fromArray([
            'static'       => true,
            'name'         => $name,
            'visibility'   => PropertyGenerator::VISIBILITY_PROTECTED,
            'docblock'     => [
                'shortDescription' => "Extension field : $name $label $type = $number",
                'tags'             => [
                    [
                        'name'        => 'var',
                        'description' => '\Protobuf\Extension',
                    ]
                ]
            ]
        ]);

        $property->getDocblock()->setWordWrap(false);

        return $property;
    }
967307
public function getFormFieldValueOptions(FieldInterface $field)
    {
        $formFieldOptions = [];
        $formFieldOptions['choices'] = array_flip($this->getFieldOptionsArray($field));
        $formFieldOptions['expanded'] = $this->isExpanded;
        $formFieldOptions['multiple'] = $this->getIsMultipleChoice($field);

        return $formFieldOptions;
    }
54876
private function getFieldOptions(ParameterModel $parameterModel, ConfigurationInterface $configuration)
    {
        $fieldOptions = [
            'required' => false,
        ];

        $parameterOptions = $parameterModel->getOptions();

        if (isset($parameterOptions['form']['options'])) {
            $fieldOptions = array_merge($fieldOptions, $parameterOptions['form']['options']);
        }
        if (!array_key_exists('label', $fieldOptions)) {
            $fieldOptions['label'] = sprintf(
                'configuration.%s.parameter.%s',
                $configuration->getName(),
                $parameterModel->getName()
            );
        }
        if (ParameterModel::TYPE_ENTITY === $parameterModel->getType() && !isset($fieldOptions['class'])) {
            $fieldOptions['class'] = $parameterOptions['class'];
        }
        if (ParameterModel::TYPE_OBJECT === $parameterModel->getType()) {
            if (!isset($fieldOptions['constraints'])) {
                $fieldOptions['constraints'] = [];
            }
            if (!is_array($fieldOptions['constraints'])) {
                $fieldOptions['constraints'] = [$fieldOptions['constraints']];
            }

            $fieldOptions['constraints'][] = new Valid();
        }

        return $fieldOptions;
    }
599500
protected function generateSetValue(Entity $entity, FieldDescriptorProto $field)
    {
        $lines      = [];
        $fieldName  = $field->getName();
        $methodName = $this->getAccessorName('set', $field);

        $lines[] = '$message->' . $methodName . '($values[\'' . $fieldName . '\']);';

        return $lines;
    }
815905
private function parseRuleParameters($field, $parameters)
    {
        // Make sure parameters is an array
        $parameters = (strpos($parameters, ',') > 0) ? explode(',', $parameters) : [$parameters];

        // Process each parameter
        foreach ($parameters as $key => $parameter)
        {
            // Replace ~table and ~field if they exist
            $parameter = str_ireplace(['~table', '~field'], [$this->getTable(), $field], $parameter);

            // Replace with attribute
            if (strpos($parameter, '~') !== false) $parameter = $this->{str_replace('~', '', $parameter)};
        }

        return $parameters;
    }
630377
public function getDataTableOptions($field, $data)
    {
        $methodName = 'get'.studly_case($this->fieldName).'DataTableOptions';

        if (!$this->model->methodExists($methodName) && !$this->model->methodExists('getDataTableOptions')) {
            throw new ApplicationException(Lang::get('backend::lang.model.missing_method', ['class' => get_class($this->model), 'method' => 'getDataTableOptions']));
        }

        if ($this->model->methodExists($methodName)) {
            $result = $this->model->$methodName($field, $data);
        }
        else {
            $result = $this->model->getDataTableOptions($this->fieldName, $field, $data);
        }

        if (!is_array($result)) {
            $result = [];
        }

        return $result;
    }
973055
protected function getValueFromReferencedEntity(FieldInterface $field)
    {
        $references = $this->model->referredIn($field->name());
        foreach ($references as $foreign => $reference) {
            $entity = $this->accessor->getPropertyValue($this->instance, $reference->container());

            if ($entity === null) {
                continue;
            }

            $value = $this->accessor->getPropertyValue($entity, $foreign);
            $this->accessor->setPropertyValue($this->instance, $field->name(), $value);
            break;
        }
    }
407846
private function retrieveFilterFieldDescription(
        AdminInterface $admin,
        string $field
    ): FieldDescriptionInterface {
        $admin->getFilterFieldDescriptions();

        $fieldDescription = $admin->getFilterFieldDescription($field);

        if (!$fieldDescription) {
            throw new \RuntimeException(sprintf('The field "%s" does not exist.', $field));
        }

        if (null === $fieldDescription->getTargetEntity()) {
            throw new \RuntimeException(sprintf('No associated entity with field "%s".', $field));
        }

        return $fieldDescription;
    }
601363
public function getManageViewParameters(BlockInterface $block)
    {
        $parameters = [
            'block_view' => $this->getView($block),
            'manage' => true,
            'manage_type' => $this->getManageFormTypeName(),
        ];

        return $parameters;
    }
499841
protected function getEntityAttributeValue($entity, $field)
    {
        $functionName = 'get'.ucfirst($field);

        $fieldValue = call_user_func([$entity, $functionName]);

        return $fieldValue;
    }
386505
public function getViewParameters(
        Action $action,
        FormInterface $form = null,
        $data = null,
        array $listRouteParameters = []
    ): array {
        $parameters = [
            'listPath' => $this->routingHelper->getAdminListPath($action->getAdmin(), $listRouteParameters),
            'admin' => $action->getAdmin(),
        ];

        if ($form) {
            $parameters['form'] = $form->createView();
        }
        if ($data) {
            $parameters['data'] = $data;
        }

        return $parameters;
    }
562507
public function getSortParameters(FieldDescriptionInterface $fieldDescription, DatagridInterface $datagrid)
    {
        return $this->baseModelManager->getSortParameters($fieldDescription, $datagrid);
    }
491575
public function fields(EntityInterface $entity)
    {
        $fields = [];
        foreach ((array)$this->getConfig('fields') as $field) {
            if (!$entity->isDirty($field)) {
                continue;
            }
            $fields[$field] = $entity->$field;
            $entity->setDirty($field, false);
        }

        return $fields;
    }