src/Twig/Extension/SonataAdminExtension.php
public function renderViewElementCompare(
        Environment $environment,
        FieldDescriptionInterface $fieldDescription,
        $baseObject,
        $compareObject
    ) {
        $template = $this->getTemplate(
            $fieldDescription,
            '@SonataAdmin/CRUD/base_show_field.html.twig',
            $environment
        );

        try {
            $baseValue = $fieldDescription->getValue($baseObject);
        } catch (NoValueException $e) {
            $baseValue = null;
        }

        try {
            $compareValue = $fieldDescription->getValue($compareObject);
        } catch (NoValueException $e) {
            $compareValue = null;
        }

        $baseValueOutput = $template->render([
            'admin' => $fieldDescription->getAdmin(),
            'field_description' => $fieldDescription,
            'value' => $baseValue,
        ]);

        $compareValueOutput = $template->render([
            'field_description' => $fieldDescription,
            'admin' => $fieldDescription->getAdmin(),
            'value' => $compareValue,
        ]);

        // Compare the rendered output of both objects by using the (possibly) overridden field block
        $isDiff = $baseValueOutput !== $compareValueOutput;

        return $this->render($fieldDescription, $template, [
            'field_description' => $fieldDescription,
            'value' => $baseValue,
            'value_compare' => $compareValue,
            'is_diff' => $isDiff,
            'admin' => $fieldDescription->getAdmin(),
        ], $environment);
    }
public function renderViewElementCompare(
        Environment $environment,
        FieldDescriptionInterface $fieldDescription,
        $baseObject,
        $compareObject
    ) {
        $template = $this->getTemplate(
            $fieldDescription,
            '@SonataAdmin/CRUD/base_show_field.html.twig',
            $environment
        );

        try {
            $baseValue = $fieldDescription->getValue($baseObject);
        } catch (NoValueException $e) {
            $baseValue = null;
        }

        try {
            $compareValue = $fieldDescription->getValue($compareObject);
        } catch (NoValueException $e) {
            $compareValue = null;
        }

        $baseValueOutput = $template->render([
            'admin' => $fieldDescription->getAdmin(),
            'field_description' => $fieldDescription,
            'value' => $baseValue,
        ]);

        $compareValueOutput = $template->render([
            'field_description' => $fieldDescription,
            'admin' => $fieldDescription->getAdmin(),
            'value' => $compareValue,
        ]);

        // Compare the rendered output of both objects by using the (possibly) overridden field block
        $isDiff = $baseValueOutput !== $compareValueOutput;

        return $this->render($fieldDescription, $template, [
            'field_description' => $fieldDescription,
            'value' => $baseValue,
            'value_compare' => $compareValue,
            'is_diff' => $isDiff,
            'admin' => $fieldDescription->getAdmin(),
        ], $environment);
    }
public function renderViewElementCompare ( Environment $ environment , FieldDescriptionInterface $ fieldDescription , $ baseObject , $ compareObject ) { $ template = $ this -> getTemplate ( $ fieldDescription , '@SonataAdmin/CRUD/base_show_field.html.twig' , $ environment ) ; try { $ baseValue = $ fieldDescription -> getValue ( $ baseObject ) ; } catch ( NoValueException $ e ) { $ baseValue = null ; } try { $ compareValue = $ fieldDescription -> getValue ( $ compareObject ) ; } catch ( NoValueException $ e ) { $ compareValue = null ; } $ baseValueOutput = $ template -> render ( [ 'admin' => $ fieldDescription -> getAdmin ( ) , 'field_description' => $ fieldDescription , 'value' => $ baseValue , ] ) ; $ compareValueOutput = $ template -> render ( [ 'field_description' => $ fieldDescription , 'admin' => $ fieldDescription -> getAdmin ( ) , 'value' => $ compareValue , ] ) ; // Compare the rendered output of both objects by using the (possibly) overridden field block $ isDiff = $ baseValueOutput !== $ compareValueOutput ; return $ this -> render ( $ fieldDescription , $ template , [ 'field_description' => $ fieldDescription , 'value' => $ baseValue , 'value_compare' => $ compareValue , 'is_diff' => $ isDiff , 'admin' => $ fieldDescription -> getAdmin ( ) , ] , $ environment ) ; }
render a compared view element.

@param mixed $baseObject
@param mixed $compareObject

@return string
render a compared view element .