If Menu is image: check file

@Assert\Callback

@author Vincent CHALAMON <vincentchalamon@gmail.com>
@param ExecutionContextInterface $context
172472
public function isImageValid(ExecutionContextInterface $context)
    {
        if ($this->isImage() && is_null($this->getFile())) {
            $context->addViolationAt('file', 'This value should not be blank.');
        }
    }
917946
public function isPublicationValid(ExecutionContextInterface $context)
    {
        // No start publication date specified for the end publication date
        if (!$this->getStartedAt() && $this->getEndedAt()) {
            $context->addViolationAt('startedAt', 'Start publication date is required when setting end publication date.');
        }
        // Start publication date is equal or later than end publication date
        if ($this->getEndedAt() && $this->getStartedAt() && $this->getStartedAt()->getTimestamp() >= $this->getEndedAt()->getTimestamp()) {
            $context->addViolationAt('endedAt', 'End publication date must be later than start publication date.');
        }
    }
14557
private function isImage(FileInterface $file) {
    $image = $this->getImage($file);

    if ($image === NULL) {
      return FALSE;
    }

    return $image->isValid();
  }
685878
public function validateEntity(ExecutionContextInterface $context)
    {
        if ($this->getType() == self::TYPE_PAGE_LINK && !$this->getNodeTranslation()) {
            $context->buildViolation('Please select a page')
              ->atPath('nodeTranslation')
              ->addViolation();
        } elseif ($this->getType() == self::TYPE_URL_LINK) {
            if (strlen($this->getTitle()) == 0) {
                $context->buildViolation('Please set the link title')
                  ->atPath('title')
                  ->addViolation();
            }
            if (strlen($this->getUrl()) == 0) {
                $context->buildViolation('Please set the link URL')
                  ->atPath('url')
                  ->addViolation();
            }
        }
    }
1072997
protected function _beforeUpdate(DatabaseContextInterface $context)
    {
        if(isset($this->order) && $this->hasProperty('ordering')) {
            $this->order($this->order);
        }
    }
1024565
protected function _afterBrowse(KControllerContextInterface $context)
    {
        $controller = $this->getController();

        if($controller->canAdd()) {
            $this->addCommand('new');
        }

        if($controller->canDelete()) {
            $this->addCommand('delete');
        }
    }
1265157
public function assemble(ContextInterface $context)
    {
        $class = ClassGenerator::fromArray(
            [
                'name' => $context->getName(),
            ]
        );
        $file = $context->getFile();
        $file->setClass($class);
        $file->setNamespace($context->getNamespace());
        $typeMap = $context->getTypeMap();
        $typeNamespace = $typeMap->getNamespace();
        $file->setUse($typeNamespace, preg_match('/\\\\Type$/', $typeNamespace) ? null : 'Type');

        try {
            $file->setUse(ClassMapCollection::class);
            $file->setUse(ClassMap::class);
            $linefeed = $file::LINE_FEED;
            $classMap = $this->assembleClassMap($typeMap, $linefeed, $file->getIndentation());
            $code = $this->assembleClassMapCollection($classMap, $linefeed).$linefeed;
            $class->addMethodFromGenerator(
                MethodGenerator::fromArray(
                    [
                        'name'       => 'getCollection',
                        'static'     => true,
                        'body'       => 'return '.$code,
                        'returntype' => ClassMapCollection::class,
                    ]
                )
            );
        } catch (\Exception $e) {
            throw AssemblerException::fromException($e);
        }
    }
1318356
public function assemble(ContextInterface $context)
    {
        $class = $context->getClass();
        $properties = $context->getType()->getProperties();
        $firstProperty = count($properties) ? current($properties) : null;

        try {
            $interfaceAssembler = new InterfaceAssembler(ResultProviderInterface::class);
            if ($interfaceAssembler->canAssemble($context)) {
                $interfaceAssembler->assemble($context);
            }

            if ($firstProperty) {
                $this->implementGetResult($context, $class, $firstProperty);
            }
        } catch (\Exception $e) {
            throw AssemblerException::fromException($e);
        }
    }
167701
protected function _beforeRender(ControllerContext $context)
    {
        $controller = $context->getSubject();

        if (!$controller->isDispatched()) {
            $controller->loadLanguage();
        }
    }
533471
public function appliesToContext(ContextInterface $context): bool
    {
        if (!$context instanceof PropertyContext) {
            return false;
        }

        $property = $context->getProperty();
        if (!preg_match($this->regex, $property->getName())) {
            return false;
        }

        return $this->subRule->appliesToContext($context);
    }
921255
public function execute($name, AnCommandContext $context)
    {
        $type = '';

        if ($context->caller) {
            $identifier = clone $context->caller->getIdentifier();

            if ($identifier->path) {
                $type = array_shift($identifier->path);
            } else {
                $type = $identifier->name;
            }
        }

        $parts = explode('.', $name);
        $method = !empty($type) ? '_'.$type.ucfirst(AnInflector::implode($parts)) : '_'.lcfirst(AnInflector::implode($parts));

        if (in_array($method, $this->getMethods())) {
            return $this->$method($context);
        }

        return true;
    }
211142
private function evalCondition(Context $context) {
		return (null !== $this->figCond) ? $this->evaluate($context, $this->figCond) : true;
	}
604662
public function checkLink(ExecutionContextInterface $context)
    {
        $violation = false;
        // check if the name is actually a fake name
        switch ($this->getLinkType()) {
            case self::TYPE_VIEW_REFERENCE:
            $violation = $this->getViewReference() == null;
                break;
            case self::TYPE_ROUTE:
            $violation = $this->getRoute() == null;
                break;
            case self::TYPE_URL:
            $violation = $this->getUrl() == null;
                break;
            case self::TYPE_WIDGET:
            $violation = $this->getAttachedWidget() == null;
                break;
            default:
                break;
        }

        if ($violation) {
            $context->buildViolation('validator.link.error.message.'.$this->getLinkType().'Missing')->addViolation();
        }
    }
188511
public function activeFor(Context $context)
    {
        switch ($this->status) {
            case self::ALWAYS_ACTIVE:
                return true;
            case self::INACTIVE:
                return false;
            case self::CONDITIONALLY_ACTIVE:
                return $this->executeCondition($context);
        }
        return false;
    }
383700
public function initialize(ContextInterface $context)
    {
        $context->setDatabase($this->databaseName);
        $context->setAjaxSteps($this->ajaxSteps);
        $context->setAjaxTimeout($this->ajaxTimeout);
        $context->setScreenshotPath($this->screenshotPath);
        $context->setRegionMap($this->regionMap);
        $context->setAdminUrl($this->adminUrl);
        $context->setLoginUrl($this->loginUrl);
    }
1330609
public function getCheckedOutDocs(OperationContextInterface $context = null)
    {
        $context = $this->ensureContext($context);
        $checkedOutDocs = $this->getBinding()->getNavigationService()->getCheckedOutDocs(
            $this->getRepositoryId(),
            $this->getId(),
            $context->getQueryFilterString(),
            $context->getOrderBy(),
            $context->isIncludeAllowableActions(),
            $context->getIncludeRelationships(),
            $context->getRenditionFilterString()
        );

        $result = [];
        $objectFactory = $this->getObjectFactory();
        foreach ($checkedOutDocs->getObjects() as $objectData) {
            $document = $objectFactory->convertObject($objectData, $context);
            if (!($document instanceof DocumentInterface)) {
                // should not happen but could happen if the repository is not implemented correctly ...
                continue;
            }

            $result[] = $document;
        }

        return $result;
    }
747823
protected function _actionAdd(AnCommandContext $context)
    {
        $entity = parent::_actionAdd($context);

        if ($entity->isPortraitable() && AnRequest::has('files.portrait')) {
            $file = AnRequest::get('files.portrait', 'raw');

            if ($this->bellowSizeLimit($file) && $file['error'] == 0) {
                $entity->setPortrait(array(
                   'url' => $file['tmp_name'],
                   'mimetype' => $file['type'],
                   )
               );
            }
        }

        return $entity;
    }