Exemplo n.º 1
0
 /**
  * @param string          $dataClass Parent entity class name
  * @param File|Attachment $entity    File entity
  * @param string          $fieldName Field name where new file/image field was added
  *
  * @return \Symfony\Component\Validator\ConstraintViolationListInterface
  */
 public function validate($dataClass, $entity, $fieldName = '')
 {
     /** @var Config $entityAttachmentConfig */
     if ($fieldName === '') {
         $entityAttachmentConfig = $this->attachmentConfigProvider->getConfig($dataClass);
         $mimeTypes = $this->getMimeArray($entityAttachmentConfig->get('mimetypes'));
         if (!$mimeTypes) {
             $mimeTypes = array_merge($this->getMimeArray($this->config->get('oro_attachment.upload_file_mime_types')), $this->getMimeArray($this->config->get('oro_attachment.upload_image_mime_types')));
         }
     } else {
         $entityAttachmentConfig = $this->attachmentConfigProvider->getConfig($dataClass, $fieldName);
         /** @var FieldConfigId $fieldConfigId */
         $fieldConfigId = $entityAttachmentConfig->getId();
         if ($fieldConfigId->getFieldType() === 'file') {
             $configValue = 'upload_file_mime_types';
         } else {
             $configValue = 'upload_image_mime_types';
         }
         $mimeTypes = $this->getMimeArray($this->config->get('oro_attachment.' . $configValue));
     }
     $fileSize = $entityAttachmentConfig->get('maxsize') * 1024 * 1024;
     foreach ($mimeTypes as $id => $value) {
         $mimeTypes[$id] = trim($value);
     }
     return $this->validator->validateValue($entity->getFile(), [new FileConstraint(['maxSize' => $fileSize, 'mimeTypes' => $mimeTypes, 'mimeTypesMessage' => 'This file type is not allowed.'])]);
 }
 /**
  * Modify menu by adding, removing or editing items.
  *
  * @param \Knp\Menu\ItemInterface $menu
  * @param array                   $options
  * @param string|null             $alias
  */
 public function build(ItemInterface $menu, array $options = array(), $alias = null)
 {
     $options['orderBy'] = array(array('field' => NavigationHistoryItem::NAVIGATION_HISTORY_COLUMN_VISIT_COUNT));
     $maxItems = $this->configOptions->get('oro_navigation.maxItems');
     if (!is_null($maxItems)) {
         $options['maxItems'] = $maxItems;
     }
     parent::build($menu, $options, $alias);
 }
Exemplo n.º 3
0
 /**
  * Test get loaded settings
  */
 public function testGetLoaded()
 {
     $loadedSettings = $this->loadedSettings;
     $repository = $this->getMockBuilder('Oro\\Bundle\\ConfigBundle\\Entity\\Repository\\ConfigRepository')->disableOriginalConstructor()->getMock();
     $repository->expects($this->at(0))->method('loadSettings')->with('user', 0)->will($this->returnValue($loadedSettings));
     $repository->expects($this->at(1))->method('loadSettings')->with('app', 0)->will($this->returnValue($loadedSettings));
     $this->om->expects($this->exactly(2))->method('getRepository')->will($this->returnValue($repository));
     $this->object->get('oro_user.level');
 }
 /**
  * Modify menu by adding, removing or editing items.
  *
  * @param \Knp\Menu\ItemInterface $menu
  * @param array                   $options
  * @param string|null             $alias
  */
 public function build(ItemInterface $menu, array $options = array(), $alias = null)
 {
     $maxItems = $this->configOptions->get('oro_navigation.maxItems');
     if (!is_null($maxItems)) {
         // we'll hide current item, so always select +1 item
         $options['maxItems'] = $maxItems + 1;
     }
     parent::build($menu, $options, $alias);
     $children = $menu->getChildren();
     foreach ($children as $child) {
         if ($this->matcher->isCurrent($child)) {
             $menu->removeChild($child);
             break;
         }
     }
     $this->getMenuManipulator()->slice($menu, 0, $maxItems);
 }
Exemplo n.º 5
0
 /**
  * {@inheritdoc}
  */
 public function buildForm(FormBuilderInterface $builder, array $options)
 {
     $builder->add('name', 'text', array('label' => 'oro.email.emailtemplate.name.label', 'required' => true));
     $builder->add('type', 'choice', array('label' => 'oro.email.emailtemplate.type.label', 'multiple' => false, 'expanded' => true, 'choices' => array('html' => 'oro.email.datagrid.emailtemplate.filter.type.html', 'txt' => 'oro.email.datagrid.emailtemplate.filter.type.txt'), 'required' => true));
     $builder->add('entityName', 'oro_entity_choice', array('label' => 'oro.email.emailtemplate.entity_name.label', 'tooltip' => 'oro.email.emailtemplate.entity_name.tooltip', 'required' => false, 'configs' => ['allowClear' => true]));
     $lang = $this->localeSettings->getLanguage();
     $notificationLangs = $this->userConfig->get('oro_locale.languages');
     $notificationLangs = array_merge($notificationLangs, [$lang]);
     $localeLabels = $this->localeSettings->getLocalesByCodes($notificationLangs, $lang);
     $builder->add('translations', 'oro_email_emailtemplate_translatation', array('label' => 'oro.email.emailtemplate.translations.label', 'required' => false, 'locales' => $notificationLangs, 'labels' => $localeLabels));
     $builder->add('parentTemplate', 'hidden', array('label' => 'oro.email.emailtemplate.parent.label', 'property_path' => 'parent'));
     // disable some fields for non editable email template
     $setDisabled = function (&$options) {
         if (isset($options['auto_initialize'])) {
             $options['auto_initialize'] = false;
         }
         $options['disabled'] = true;
     };
     $factory = $builder->getFormFactory();
     $builder->addEventListener(FormEvents::PRE_SET_DATA, function (FormEvent $event) use($factory, $setDisabled) {
         $data = $event->getData();
         if ($data && $data->getId() && $data->getIsSystem()) {
             $form = $event->getForm();
             // entityName field
             $options = $form->get('entityName')->getConfig()->getOptions();
             $setDisabled($options);
             $form->add($factory->createNamed('entityName', 'oro_entity_choice', null, $options));
             // name field
             $options = $form->get('name')->getConfig()->getOptions();
             $setDisabled($options);
             $form->add($factory->createNamed('name', 'text', null, $options));
             if (!$data->getIsEditable()) {
                 // name field
                 $options = $form->get('type')->getConfig()->getOptions();
                 $setDisabled($options);
                 $form->add($factory->createNamed('type', 'choice', null, $options));
             }
         }
     });
 }
Exemplo n.º 6
0
 /**
  * @param $route
  * @return array
  */
 protected function getBreadcrumbs($route)
 {
     return $this->breadcrumbManager->getBreadcrumbLabels($this->userConfigManager->get('oro_navigation.breadcrumb_menu'), $route);
 }