Generate index view

@param AbstractResourceBundle $bundle
@param array                  $summary

@return array
192379
protected function generateIndexView(AbstractResourceBundle $bundle, &$summary)
    {
        $path = $bundle->getPath() . '/Resources/views/' . $this->model . '/index.html.twig';

        if (file_exists($path)) {
            $summary[] = '';
            $summary[] = '<bg=red>Index view already exist.</>';

            return;
        }

        $this->renderFile('crud/index.html.twig.twig',
            $path,
            array(
                'bundle'  => $bundle->getName(),
                'model'   => $this->model,
                'prefix'  => $this->getBundlePrefix($bundle),
                'vars'    => strtolower(Inflector::pluralize($this->model)),
                'actions' => array(
                    'add' => strtolower($this->getBundlePrefix($bundle) . '_' . $this->model . '_create')
                )
            )
        );

        $summary[] = '';
        $summary[] = '<bg=green>Index view created.</>';
    }
1171237
protected function generateShowView(AbstractResourceBundle $bundle, &$summary)
    {
        $path = $bundle->getPath() . '/Resources/views/' . $this->model . '/show.html.twig';
        $entityClass = $this->getContainer()->get('doctrine')->getAliasNamespace($this->bundle->getName()) . '\\' . $this->model;
        $identifier = $this->getContainer()->get('doctrine')
            ->getManager()
            ->getClassMetadata($entityClass)
            ->getIdentifier();

        if (file_exists($path)) {
            $summary[] = '';
            $summary[] = '<bg=red>Show view already exist.</>';

            return;
        }

        $this->renderFile('crud/show.html.twig.twig',
            $path,
            array(
                'bundle'     => $bundle->getName(),
                'model'      => $this->model,
                'identifier' => $identifier[0],
                'prefix'     => $this->getBundlePrefix($bundle),
                'cancel'     => strtolower($this->getBundlePrefix($bundle) . '_' . $this->model . '_index'),
                'actions'    => array(
                    'edit' => strtolower($this->getBundlePrefix($bundle) . '_' . $this->model . '_update')
                )
            )
        );

        $summary[] = '';
        $summary[] = '<bg=green>Show view created.</>';
    }
941145
private function getBundleValue(ResourceBundleInterface $bundle, string $key): array
    {
        return [
            BundleStorageInterface::INDEX_PAIR_VALUE  => $bundle->getValue($key),
            BundleStorageInterface::INDEX_PAIR_LOCALE => $bundle->getLocale(),
        ];
    }
660749
protected function getRequiredBundleGenerators($bundle)
    {
        return [
            $this->createZedBundleCodeGenerator($bundle),
            $this->createYvesBundleCodeGenerator($bundle),
            $this->createClientBundleCodeGenerator($bundle),
            $this->createServiceBundleCodeGenerator($bundle),
            $this->createSharedBundleCodeGenerator($bundle),
        ];
    }
1081534
protected function generateTypeList($entity_type, $bundle_type, $entity_add_form, $bundle_add_form, NodeInterface $node, $field) {
    $type_definition = $this->entityTypeManager->getDefinition($bundle_type);

    $build = [
      '#theme' => 'entity_add_list',
      '#bundles' => [],
      '#cache' => ['tags' => $type_definition->getListCacheTags()],
    ];

    $bundles = $this->entityTypeManager->getStorage($bundle_type)->loadMultiple();
    $access_control_handler = $this->entityTypeManager->getAccessControlHandler($entity_type);

    foreach (array_keys($bundles) as $bundle_id) {
      $bundle = $bundles[$bundle_id];

      // Skip bundles that don't have the specified field.
      $fields = $this->entityFieldManager->getFieldDefinitions($entity_type, $bundle_id);
      if (!isset($fields[$field])) {
        continue;
      }

      $build['#bundles'][$bundle_id] = [
        'label' => $bundle->label(),
        'description' => $bundle->getDescription(),
        'add_link' => Link::createFromRoute(
          $bundle->label(),
          $entity_add_form,
          [$bundle_type => $bundle->id()],
          ['query' => ["edit[$field][widget][0][target_id]" => $node->id()]]
        ),
      ];
    }

    // Filter out bundles the user can't create.
    foreach (array_keys($bundles) as $bundle_id) {
      $access = $access_control_handler->createAccess($bundle_id, NULL, [], TRUE);
      if (!$access->isAllowed()) {
        unset($build['#bundles'][$bundle_id]);
      }
      $this->renderer->addCacheableDependency($build, $access);
    }

    // Build the message shown when there are no bundles.
    $type_label = $type_definition->getLowercaseLabel();
    $link_text = $this->t('Add a new @entity_type.', ['@entity_type' => $type_label]);
    $build['#add_bundle_message'] = $this->t('There is no @entity_type yet. @add_link', [
      '@entity_type' => $type_label,
      '@add_link' => Link::createFromRoute($link_text, $bundle_add_form)->toString(),
    ]);

    return $build;
  }
925615
public function addBundle(Bundle $bundle)
    {
        foreach ($bundle as $resource) {
            if (is_string($resource)) {
                $this->addFile($resource);
            } else {
                $this->buildFromIterator($resource);
            }
        }
    }
827632
public function generateMigrationQueries(Bundle $bundle, AbstractPlatform $platform)
    {
        $schemas = $this->getSchemas();
        $fromSchema = $schemas['fromSchema'];
        $toSchema = $schemas['toSchema'];

        $bundleTables = $this->getBundleTables($bundle, $schemas['metadata']);
        $this->filterSchemas(array($fromSchema, $toSchema), $bundleTables);

        $upQueries = $fromSchema->getMigrateToSql($toSchema, $platform);
        $downQueries = $fromSchema->getMigrateFromSql($toSchema, $platform);

        return array(
            self::QUERIES_UP => $upQueries,
            self::QUERIES_DOWN => $downQueries
        );
    }
732418
public function getAttributeIds($bundle = null)
    {
        $attributes = $this->attributes($bundle);
        $ids = [];

        foreach ($attributes as $name => $info) {
            $ids[] = $info['id'];
        }

        return $ids;
    }
416720
@Override
	public void processBundles(GlobalPreprocessingContext ctx, List<JoinableResourceBundle> bundles) {

		ResourceReaderHandler rsHandler = ctx.getRsReaderHandler();

		Set<String> resourcePaths = getResourcePaths(bundles);
		JawrConfig jawrConfig = ctx.getJawrConfig();
		Charset charset = jawrConfig.getResourceCharset();

		BinaryResourcesHandler binaryRsHandler = (BinaryResourcesHandler) jawrConfig.getContext()
				.getAttribute(JawrConstant.BINARY_CONTEXT_ATTRIBUTE);

		generateSprites(rsHandler, binaryRsHandler, resourcePaths, jawrConfig, charset);

		// Update CSS resource handler
		CssSmartSpritesResourceReader cssSpriteResourceReader = new CssSmartSpritesResourceReader(
				rsHandler.getWorkingDirectory(), jawrConfig);

		updateBundlesDirtyState(bundles, cssSpriteResourceReader);

		ctx.getRsReaderHandler().addResourceReader(cssSpriteResourceReader);

		// Update image resource handler
		ResourceReaderHandler imgStreamRsHandler = binaryRsHandler.getRsReaderHandler();
		imgStreamRsHandler.addResourceReader(cssSpriteResourceReader);
	}
1271763
private function listComponents(string $interface, string $title, string $description): ResponseInterface
    {
        $uses_access  = in_array($interface, self::COMPONENTS_WITH_ACCESS, true);
        $uses_sorting = in_array($interface, self::COMPONENTS_WITH_SORT, true);

        return $this->viewResponse('admin/components', [
            'description'  => $description,
            'interface'    => $interface,
            'modules'      => $this->module_service->findByInterface($interface, true, true),
            'title'        => $title,
            'trees'        => Tree::all(),
            'uses_access'  => $uses_access,
            'uses_sorting' => $uses_sorting,
        ]);
    }
466179
protected function installDefaultPageTemplates($bundle)
    {
        // Configuration templates
        if ($this->isSymfony4()) {
            $dirPath = $this->container->getParameter('kernel.project_dir') . '/config/kunstmaancms/pagetemplates/';
        } else {
            $dirPath = sprintf('%s/Resources/config/pagetemplates/', $bundle->getPath());
        }

        $skeletonDir = sprintf('%s/Resources/config/pagetemplates/', GeneratorUtils::getFullSkeletonPath('/common'));

        // Only copy templates over when the folder does not exist yet...
        if (!$this->filesystem->exists($dirPath)) {
            $files = array(
                'default-one-column.yml',
                'default-two-column-left.yml',
                'default-two-column-right.yml',
                'default-three-column.yml',
            );
            foreach ($files as $file) {
                $this->filesystem->copy($skeletonDir . $file, $dirPath . $file, false);
                GeneratorUtils::replace('~~~BUNDLE~~~', $bundle->getName(), $dirPath . $file);
            }
        }

        // Twig templates
        $dirPath = $this->getTemplateDir($bundle) . '/Pages/Common/';

        $skeletonDir = sprintf('%s/Resources/views/Pages/Common/', GeneratorUtils::getFullSkeletonPath('/common'));

        if (!$this->filesystem->exists($dirPath)) {
            $files = array(
                'one-column-pagetemplate.html.twig',
                'two-column-left-pagetemplate.html.twig',
                'two-column-right-pagetemplate.html.twig',
                'three-column-pagetemplate.html.twig',
            );
            foreach ($files as $file) {
                $this->filesystem->copy($skeletonDir . $file, $dirPath . $file, false);
            }
            $this->filesystem->copy($skeletonDir . 'view.html.twig', $dirPath . 'view.html.twig', false);
        }

        $contents = file_get_contents($dirPath . 'view.html.twig');

        $twigFile = $this->isSymfony4() ?
            $twigFile = "{% extends 'Layout/layout.html.twig' %}\n" :
            $twigFile = "{% extends '".$bundle->getName().":Layout:layout.html.twig' %}\n"
        ;

        if (strpos($contents, '{% extends ') === false) {
            GeneratorUtils::prepend(
                $twigFile,
                $dirPath . 'view.html.twig'
            );
        }
    }
58062
protected function getSkeletonDirs(BundleInterface $bundle = null)
    {
        $baseSkeletonDirs = parent::getSkeletonDirs($bundle);
        $skeletonDirs = array();

        if (is_dir($dir = $this->getContainer()->get('kernel')->getRootdir().'/Resources/MultiUserBundleMultiUserBundle/skeleton')) {
            $skeletonDirs[] = $dir;
        }

        $reflClass = new \ReflectionClass($this);
        $dir = dirname($reflClass->getFileName());

        $skeletonDirs[] = $dir.'/../Resources/skeleton';
        $skeletonDirs[] = $dir.'/../Resources';

        return array_merge($skeletonDirs, $baseSkeletonDirs);
    }
741305
public function getMigrationStatus(Bundle $bundle)
    {
        $config = $this->getConfiguration($bundle);

        if (is_dir($config->getMigrationsDirectory())) {
            $currentVersion = $config->getCurrentVersion();
            $availableVersions = $config->getAvailableVersions();
            array_unshift($availableVersions, '0');
        } else {
            $currentVersion = '0';
            $availableVersions = [];
        }

        return [
            self::STATUS_CURRENT => $currentVersion,
            self::STATUS_AVAILABLE => $availableVersions,
            self::VERSION_LATEST => $config->getLatestVersion(),
        ];
    }
1265770
public function getClientMapping(array $bundles)
    {
        /** @var array $typesMapping Array of filtered mappings for the elasticsearch client*/
        $typesMapping = null;

        /** @var array $mappings All mapping info */
        $mappings = $this->getMappings($bundles);

        foreach ($mappings as $type => $mapping) {
            if (!empty($mapping['properties'])) {
                $typesMapping[$type] = array_filter(
                    array_merge(
                        ['properties' => $mapping['properties']],
                        $mapping['fields']
                    ),
                    function ($value) {
                        return (bool)$value || is_bool($value);
                    }
                );
            }
        }

        return $typesMapping;
    }
467529
protected function generateIndexView($dir)
    {
        $parts = explode('\\', $this->entity);
        $entityClass = array_pop($parts);

        $this->renderFile(
            'views/index.html.twig',
            $dir.'/index.html.twig',
            array(
                'dir' => $this->skeletonDir,
                'entity' => $this->entity,
                'fields' => $this->metadata->fieldMappings,
                'actions' => $this->actions,
                'record_actions' => $this->getRecordActions(),
                'route_prefix' => $this->routePrefix,
                'route_name_prefix' => $this->routeNamePrefix,
                'bundle' => $this->bundle->getName(),
                'entity_class' => $entityClass,
            )
        );
    }
1019189
private function find(BundleInterface $bundle)
    {
        $yamls =  array();

        if (!is_dir($bundle->getPath().'/Resources/config')) {
            return $yamls;
        }

        $finder = new Finder();
        $finder->files()
               ->name('*-generator.yml')
               ->in($bundle->getPath().'/Resources/config');

        foreach ($finder as $file) {
            $yamls[$file->getRealPath()] = $file->getRealPath();
        }

        return $yamls;
    }
808642
protected void renderBundleLinks(JoinableResourceBundle bundle, BundleRendererContext ctx,
			Map<String, String> variant, Writer out, boolean debugOn) throws IOException {

		ResourceBundlePathsIterator it = bundler.getBundlePaths(bundle.getId(), new ConditionalCommentRenderer(out),
				variant);
		renderBundleLinks(it, ctx, debugOn, out);
	}