Añade todos los widgets de un tipo
@param type $type
@return int
@throws \Symfony\Component\Security\Core\Exception\AccessDeniedException
513521
public function addAll($type,$nameFilter = null) {
        $definitionBlockGrid = $this->getDefinitionBlockGrid($type);
        if($definitionBlockGrid->hasPermission() == false){
            throw new \Symfony\Component\Security\Core\Exception\AccessDeniedException();
        }
        $events = $definitionBlockGrid->getParseEvents();
        $names = $definitionBlockGrid->getNames();
        
        $templates = $definitionBlockGrid->getTemplates();
        
        $templatesKeys = array_keys($templates);
        $widgetBoxManager = $this->getWidgetBoxManager();
        $i = 0;
        foreach ($names as $name => $value) {
            if($definitionBlockGrid->hasPermission($name) === false){
                continue;
            }
            if($nameFilter !== null && $name !== $nameFilter){
                continue;
            }
            if(($blockWidgetBox = $this->isAdded($type, $name)) !== null){
                $this->getWidgetBoxManager()->remove($blockWidgetBox);
                //continue;
            }
            $blockWidgetBox = $widgetBoxManager->buildBlockWidget();
            $blockWidgetBox->setType($type);
            $blockWidgetBox->setName($name);
            $blockWidgetBox->setSetting('template',$templatesKeys[0]);
            $blockWidgetBox->setEvent($events[0]);
            $blockWidgetBox->setCreatedAt(new \DateTime());
            $blockWidgetBox->setEnabled(true);
            $widgetBoxManager->save($blockWidgetBox);
            $i++;
        }
        return $i;
    }
99449
public function get($type)
    {
        if (!isset($this->instances[$type])) {

            if (!isset($this->services[$type])) {
                if ($this->debug) {
                    trigger_error(sprintf("Widget type '%s' does not exist, returning a null implementation", $type), E_USER_ERROR);
                }
                // This primarily meant to display stuff, we should never WSOD
                // in the user's face, return a null object instead that will
                // UI operations smooth and error tolerant.
                return new NullWidget();
            }

            $this->instances[$type] = $this->container->get($this->services[$type]);
        }

        return $this->instances[$type];
    }
1141655
protected function resolveWidget($type)
    {
        if ($this->widgetFactory()->isResolvable($type)) {
            return $this->widgetFactory()->create($type);
        } else {
            throw new InvalidArgumentException(sprintf(
                'Invalid widget UI. Must be an instance of %s',
                WidgetInterface::class
            ));
        }
    }
59054
public function getWeight($type)
    {
        if (isset($this->weights[$type])) {
            return $this->weights[$type];
        }

        return null;
    }
1296684
protected function getJoinTable($type)
    {
        switch ($type) {
            case self::DELETE:
                // Delete uses edit type - Drop through
            case self::EDIT:
                return $this->getEditorGroupsTable();
            case self::VIEW:
                return $this->getViewerGroupsTable();
            default:
                throw new InvalidArgumentException("Invalid argument type $type");
        }
    }
927921
public function fetchAll($type = self::FETCH_TYPE_NUM)
    {
        if ($this->_allFetched) {
            return $this->buffer;
        }
        $results = $this->statement->fetchAll($type);
        if ($results !== false) {
            $this->buffer = array_merge($this->buffer, $results);
        }
        $this->_allFetched = true;
        $this->statement->closeCursor();

        return $this->buffer;
    }
1238284
public function browserAction()
    {
        if (false === $this->admin->isGranted('LIST')) {
            throw new AccessDeniedException();
        }

        $datagrid = $this->admin->getDatagrid();
        $datagrid->setValue('context', null, $this->admin->getPersistentParameter('context'));
        $datagrid->setValue('providerName', null, $this->admin->getPersistentParameter('provider'));

        // Store formats
        $formats = array();
        foreach ($datagrid->getResults() as $media) {
            $formats[$media->getId()] = $this->get('sonata.media.pool')->getFormatNamesByContext($media->getContext());
        }

        $formView = $datagrid->getForm()->createView();

        // set the theme for the current Admin Form
        $this->setFormTheme($formView, $this->admin->getFilterTheme());

        return $this->render($this->getTemplate('browser'), array(
            'action' => 'browser',
            'form' => $formView,
            'datagrid' => $datagrid,
            'formats' => $formats,
            'base_template' => $this->getTemplate('layout'),
        ));
    }
1297727
private function lookupEntityName($type)
    {
        $module = $this->moduleManager->getModule($type);

        if (!$module instanceof NodeModuleInterface) {
            throw new \Exception(sprintf('Type "%s" is not a NodeModule.', $type));
        }

        return $module->getEntityName();
    }
1270163
public function uploadAction(Request $request, $type = 'image')
    {
        $this->checkIfMediaBundleIsLoaded();

        if (false === $this->admin->checkAccess('CREATE')) {
            throw new AccessDeniedException();
        }

	    /** @var $mediaAdmin \Sonata\MediaBundle\Admin\ORM\MediaAdmin */
	    $mediaAdmin = $this->container->get('sonata.media.admin.media');

	    $mediaAdmin->setRequest($request);

        $provider = $request->get('provider');
        $file = $request->files->get('upload');

	    $message = $this->admin->trans(
		    'The file is not readable.',[], 'validators'
	    );
	    $response = ['uploaded' => 0, 'error'  => ['message' =>  $message]];


        if (!$provider || null === $file) {
	        return new JsonResponse($response);
        }

        if ($file instanceof UploadedFile && $file->isValid()) {

            try {
                $context = $request->get('context', $this->get('sonata.media.pool')->getDefaultContext());

	            /** @var Media $media */
	            $media = $mediaAdmin->getNewInstance();
	            $media->setEnabled(true);
	            $media->setName($file->getClientOriginalName());
                $media->setBinaryContent($file);
                $media->setContext($context);
                $media->setProviderName($provider);


	            $provider = $mediaAdmin->getPool()->getProvider($provider);

	            $provider->transform($media);

	            $validator = $this->container->get('validator');

	            $errors = $validator->validate($media);

	            if ($errors->count() > 0) {
		            $duplicate = false;
		            foreach ($errors as $error) {
			            $errorMessages[] = $error->getMessage();

			            if ($error->getMessage() == 'File is duplicate') {
				            $duplicate = true;
			            }
		            }

		            if ($duplicate) {
			            $originalMedia = $mediaAdmin->checkForDuplicate($media);
			            $path = $provider->generatePublicUrl($originalMedia, 'reference');
			            $response = [
			            	'uploaded' => 1,
				            'fileName' => $originalMedia->getMetadataValue('filename'),
				            'url' => $path,
				            'error'  => ['message' => 'duplicate media']];
		            }else{
			            $response = ['uploaded' => 0, 'error'  => ['message' =>  implode(', ', $errorMessages)]];
		            }

		            return new JsonResponse($response);
	            }

	            try {
		            $mediaAdmin->create($media);
		            $path = $provider->generatePublicUrl($media, 'reference');
                    $response = ['uploaded' => 1, 'fileName' => $media->getMetadataValue('filename'), 'url' => $path ];
	            } catch (\Exception $e) {
		            $response = ['uploaded' => 0, 'error'  => ['message' => $e->getMessage()]];
	            }

            } catch (\Exception $e) {

	            $response = ['uploaded' => 0, 'error'  => ['message' => $e->getMessage()]];
            } catch (\Throwable $e) {
	            $response = ['uploaded' => 0, 'error'  => ['message' => $e->getMessage()]];
            }
        } elseif ($file instanceof UploadedFile && !$file->isValid()) {

	        $response = ['uploaded' => 0, 'error'  => ['message' =>  $file->getError()]];
        } else {
            $message = $this->admin->trans(
                'error.file_upload_size',
                ['%max_server_size%' => ini_get('upload_max_filesize')], 'media'
            );

	        $response = ['uploaded' => 0, 'error'  => ['message' =>  $message]];
        }

        return new JsonResponse($response);
    }
890830
public static function getTableName($type = 'access')
    {
        if (isset(self::$tables[$type])) {
            return self::$tables[$type];
        } else {
            throw new \InvalidArgumentException($type);
        }
    }
576557
public function isAdded($type, $name) {
        $widget = $this->getWidgetBoxManager()->findPublishedByTypeAndName($type, $name);
        return $widget;
    }
413949
protected function getType($type)
    {
        if (isset($this->typeAlias[$type])) {
            return $this->typeAlias[$type];
        }

        return $type;
    }
1112694
public static function get($type)
    {
        $instance = null;

        switch ($type) {

            case 'IM/Send':
                $instance = new SendService();
                break;

            case 'IM/Status':
                $instance = new StatusService();
                break;

            case 'TFA/Request':
                $instance = new RequestService();
                break;

            case 'TFA/Validate':
                $instance = new ValidateService();
                break;

            default:
                throw new \Exception("Error - Unknow service", 1);

        }
        return $instance;
    }
1016764
public function getMappedType($type)
    {
        if ($this->hasMappedType($type)) {
            return $this->mappedTypes[$type];
        }

        if ($this->useStrictTypeMapping) {
            throw PlatformException::mappedTypeDoesNotExist($type);
        }

        return $this->fallbackMappedType;
    }
750580
public function count($type = 'admin.web')
    {

        return $this->calendar
            ->scopeQuery(function ($query) use ($type) {
                return $query->where('status', '<>', 'Draft')
                    ->whereUserId(user_id($type))
                    ->whereUserType(user_type($type));
            })->count();
    }
446312
public function get($type)
    {
        $sum = 0;
        $now = $this->getTimeInMilliseconds();

        for ($i = 0; $i < $this->rollingStatisticalWindowBuckets; $i++) {
            $bucketIndex = $this->getBucketIndex($i, $now);
            $sum += $this->stateStorage->getBucket($this->commandKey, $type, $bucketIndex);
        }

        return $sum;
    }
402027
public function getSdk($type) {
    $network_manager = $this->networkManager->createInstance('social_auth_facebook');

    if (!$network_manager->isActive()) {
      drupal_set_message($this->t('@network is disabled. Contact the site administrator', [
        '@network' => $this->t('Facebook'),
      ]), 'error');
      return $this->redirect('user.' . $type);
    }

    if (!$sdk = $network_manager->getSdk()) {
      drupal_set_message($this->t('@network Auth not configured properly. Contact the site administrator.', [
        '@network' => $this->t('Facebook'),
      ]), 'error');
      return $this->redirect('user.' . $type);
    }

    return $sdk;
  }