src/Contao/View/Contao2BackendView/EditMask.php
protected function allValuesUnique()
    {
        // Init some vars.
        $environment     = $this->getEnvironment();
        $translator      = $environment->getTranslator();
        $dataProvider    = $environment->getDataProvider($this->model->getProviderName());
        $editInformation = $GLOBALS['container']['dc-general.edit-information'];

        // Run each and check the unique flag.
        foreach ($this->getDataDefinition()->getPropertiesDefinition()->getPropertyNames() as $propertyName) {
            $definition = $this->getDataDefinition()->getPropertiesDefinition()->getProperty($propertyName);
            $extra      = $definition->getExtra();
            $value      = $this->model->getProperty($propertyName);

            // Check the flag and the value.
            if (('' !== $value) && $extra['unique'] && isset($extra['unique'])) {
                // Check the database. If return true the value is already in the database.
                if (!$dataProvider->isUniqueValue($propertyName, $value, $this->model->getId())) {
                    $editInformation->setModelError(
                        $this->model,
                        [$translator->translate('not_unique', 'MSC', [$propertyName])],
                        $definition
                    );

                    return false;
                }
            }
        }

        return true;
    }
protected function allValuesUnique()
    {
        // Init some vars.
        $environment     = $this->getEnvironment();
        $translator      = $environment->getTranslator();
        $dataProvider    = $environment->getDataProvider($this->model->getProviderName());
        $editInformation = $GLOBALS['container']['dc-general.edit-information'];

        // Run each and check the unique flag.
        foreach ($this->getDataDefinition()->getPropertiesDefinition()->getPropertyNames() as $propertyName) {
            $definition = $this->getDataDefinition()->getPropertiesDefinition()->getProperty($propertyName);
            $extra      = $definition->getExtra();
            $value      = $this->model->getProperty($propertyName);

            // Check the flag and the value.
            if (('' !== $value) && $extra['unique'] && isset($extra['unique'])) {
                // Check the database. If return true the value is already in the database.
                if (!$dataProvider->isUniqueValue($propertyName, $value, $this->model->getId())) {
                    $editInformation->setModelError(
                        $this->model,
                        [$translator->translate('not_unique', 'MSC', [$propertyName])],
                        $definition
                    );

                    return false;
                }
            }
        }

        return true;
    }
protected function allValuesUnique ( ) { // Init some vars. $ environment = $ this -> getEnvironment ( ) ; $ translator = $ environment -> getTranslator ( ) ; $ dataProvider = $ environment -> getDataProvider ( $ this -> model -> getProviderName ( ) ) ; $ editInformation = $ GLOBALS [ 'container' ] [ 'dc-general.edit-information' ] ; // Run each and check the unique flag. foreach ( $ this -> getDataDefinition ( ) -> getPropertiesDefinition ( ) -> getPropertyNames ( ) as $ propertyName ) { $ definition = $ this -> getDataDefinition ( ) -> getPropertiesDefinition ( ) -> getProperty ( $ propertyName ) ; $ extra = $ definition -> getExtra ( ) ; $ value = $ this -> model -> getProperty ( $ propertyName ) ; // Check the flag and the value. if ( ( '' !== $ value ) && $ extra [ 'unique' ] && isset ( $ extra [ 'unique' ] ) ) { // Check the database. If return true the value is already in the database. if ( ! $ dataProvider -> isUniqueValue ( $ propertyName , $ value , $ this -> model -> getId ( ) ) ) { $ editInformation -> setModelError ( $ this -> model , [ $ translator -> translate ( 'not_unique' , 'MSC' , [ $ propertyName ] ) ] , $ definition ) ; return false ; } } } return true ; }
Check if all values are unique, but only for the fields which have the option enabled.

@return bool True => everything is okay | False => One value is not unique.

@SuppressWarnings(PHPMD.Superglobals)
Check if all values are unique but only for the fields which have the option enabled .