Validates the raw field map and creates a map suitable for ObjectType

@param  Manager $manager
@return array
970284
protected function createFields(Manager $manager)
    {
        $fieldMap = [];
        $instance = $this->getDataObjectInstance();
        $extraDataObjects = $this->nestedDataObjectClasses();
        $this->fields->removeDuplicates('Name');

        if (!$this->fields->exists()) {
            $this->addFields(
                Config::inst()->get(self::class, 'default_fields')
            );
        }

        $resolver = function ($obj, $args, $context, $info) {
            /**
             * @var DataObject $obj
             */
            $field = $obj->obj($info->fieldName);
            // return the raw field value, or checks like `is_numeric()` fail
            if ($field instanceof DBField && $field->isInternalGraphQLType()) {
                return $field->getValue();
            }
            return $field;
        };

        foreach ($this->fields as $fieldData) {
            $fieldName = $fieldData->Name;
            if (!StaticSchema::inst()->isValidFieldName($instance, $fieldName)) {
                throw new InvalidArgumentException(
                    sprintf(
                        'Invalid field "%s" on %s',
                        $fieldName,
                        $this->getDataObjectClass()
                    )
                );
            }

            $result = $instance->obj($fieldName);

            if ($result instanceof SS_List) {
                throw new InvalidArgumentException(
                    sprintf(
                        'Fieldname %s added to %s returns a list. This should be defined as a nested query using addNestedQuery(%s)',
                        $fieldName,
                        $this->getDataObjectClass(),
                        $fieldName
                    )
                );
            }

            if ($result instanceof DBField) {
                /** @var DBField|TypeCreatorExtension $result */
                $fieldMap[$fieldName] = [];
                $fieldMap[$fieldName]['type'] = $result->getGraphQLType($manager);
                $fieldMap[$fieldName]['resolve'] = $resolver;
                $fieldMap[$fieldName]['description'] = $fieldData->Description;
            }
        }

        foreach ($extraDataObjects as $fieldName => $className) {
            $description = $this->getFieldDescription($fieldName);
            $fieldMap[$fieldName] = [
                'type' => StaticSchema::inst()->fetchFromManager($className, $manager),
                'description' => $description,
                'resolve' => $resolver,
            ];
        }

        foreach ($this->nestedQueries as $name => $scaffolder) {
            $scaffold = $scaffolder->scaffold($manager);
            $scaffold['name'] = $name;
            $fieldMap[$name] = $scaffold;
        }

        return $fieldMap;
    }
169134
public function load(ObjectManager $manager)
    {
        /**
         * @var ProductInterface  $productWithVariants
         * @var CurrencyInterface $currency
         * @var ObjectDirector    $variantDirector
         */
        $currency = $this->getReference('currency-dollar');
        $productWithVariants = $this->getReference('product-with-variants');
        $variantDirector = $this->getDirector('product_variant');

        /**
         * @var ValueInterface $optionWhite
         * @var ValueInterface $optionRed
         * @var ValueInterface $optionSmall
         * @var ValueInterface $optionLarge
         */
        $optionWhite = $this->getReference('value-color-white');
        $optionRed = $this->getReference('value-color-red');
        $optionSmall = $this->getReference('value-size-small');
        $optionLarge = $this->getReference('value-size-large');

        /**
         * Variant White-Small.
         */
        $variantWhiteSmall = $variantDirector
            ->create()
            ->setSku('variant-white-small-sku')
            ->setStock(100)
            ->setProduct($productWithVariants)
            ->addOption($optionWhite)
            ->addOption($optionSmall)
            ->setPrice(Money::create(1500, $currency))
            ->setHeight(13)
            ->setWidth(12)
            ->setDepth(19)
            ->setWeight(125)
            ->setEnabled(true);

        $productWithVariants->setPrincipalVariant($variantWhiteSmall);

        $variantDirector->save($variantWhiteSmall);
        $this->addReference('variant-white-small', $variantWhiteSmall);

        /**
         * Variant White-Large.
         */
        $variantWhiteLarge = $variantDirector
            ->create()
            ->setSku('variant-white-large-sku')
            ->setStock(100)
            ->setProduct($productWithVariants)
            ->addOption($optionWhite)
            ->addOption($optionLarge)
            ->setPrice(Money::create(1800, $currency))
            ->setHeight(12)
            ->setWidth(11)
            ->setDepth(45)
            ->setWeight(155)
            ->setEnabled(true);

        $variantDirector->save($variantWhiteLarge);
        $this->addReference('variant-white-large', $variantWhiteLarge);

        /**
         * Variant Red-Small.
         */
        $variantRedSmall = $variantDirector
            ->create()
            ->setSku('variant-red-small-sku')
            ->setStock(100)
            ->setProduct($productWithVariants)
            ->addOption($optionRed)
            ->addOption($optionSmall)
            ->setPrice(Money::create(1500, $currency))
            ->setHeight(19)
            ->setWidth(9)
            ->setDepth(33)
            ->setWeight(1000)
            ->setEnabled(true);

        $this->storeProductImage(
            $variantRedSmall,
            'variant.jpg'
        );

        $variantDirector->save($variantRedSmall);
        $this->addReference('variant-red-small', $variantRedSmall);

        /**
         * Variant Red-Large.
         */
        $variantRedLarge = $variantDirector
            ->create()
            ->setSku('variant-red-large-sku')
            ->setStock(100)
            ->setProduct($productWithVariants)
            ->addOption($optionRed)
            ->addOption($optionLarge)
            ->setPrice(Money::create(1800, $currency))
            ->setHeight(50)
            ->setWidth(30)
            ->setDepth(18)
            ->setWeight(70)
            ->setEnabled(true);

        $variantDirector->save($variantRedLarge);
        $this->addReference('variant-red-large', $variantRedLarge);
    }
1143421
protected function registerFixedTypes(Manager $manager)
    {
        $fixedTypes = Config::inst()->get(self::class, 'fixed_types');
        if ($fixedTypes) {
            if (!is_array($fixedTypes)) {
                throw new Exception(
                    sprintf(
                        '%s.fixed_types must be an array',
                        __CLASS__
                    )
                );
            }
            foreach ($fixedTypes as $className) {
                $instance = Injector::inst()->get($className);
                if (!$instance instanceof ViewableData) {
                    throw new Exception(
                        sprintf(
                            'Cannot auto register class %s. It is not a subclass of %s',
                            $className,
                            ViewableData::class
                        )
                    );
                }
                if (!$instance->hasExtension(TypeCreatorExtension::class)) {
                    throw new Exception(
                        sprintf(
                            'Cannot auto register class %s. Is does not have the extension %s.',
                            $className,
                            TypeCreatorExtension::class
                        )
                    );
                }
                $instance->addToManager($manager);
            }
        }
    }
116226
public function load(ObjectManager $manager)
    {
        /**
         * Product.
         *
         * @var CategoryInterface     $category
         * @var ManufacturerInterface $manufacturer
         * @var CurrencyInterface     $currency
         * @var ObjectDirector        $productDirector
         */
        $category = $this->getReference('category');
        $rootCategory = $this->getReference('rootCategory');
        $manufacturer = $this->getReference('manufacturer');
        $currency = $this->getReference('currency-dollar');
        $productDirector = $this->getDirector('product');

        $product = $productDirector
            ->create()
            ->setName('product')
            ->setSlug('product')
            ->setDescription('my product description')
            ->setShortDescription('my product short description')
            ->addCategory($category)
            ->setPrincipalCategory($category)
            ->setManufacturer($manufacturer)
            ->setStock(10)
            ->setPrice(Money::create(1000, $currency))
            ->setSku('product-sku-code-1')
            ->setHeight(10)
            ->setWidth(15)
            ->setDepth(20)
            ->setWeight(100)
            ->setEnabled(true);

        $productDirector->save($product);
        $this->addReference('product', $product);

        /**
         * Reduced Product.
         */
        $productReduced = $productDirector
            ->create()
            ->setName('product-reduced')
            ->setSlug('product-reduced')
            ->setDescription('my product-reduced description')
            ->setShortDescription('my product-reduced short description')
            ->setShowInHome(true)
            ->setStock(5)
            ->setPrice(Money::create(1000, $currency))
            ->setReducedPrice(Money::create(500, $currency))
            ->setHeight(25)
            ->setWidth(30)
            ->setDepth(35)
            ->setWeight(200)
            ->setEnabled(true);

        $this->storeProductImage(
            $productReduced,
            'product.jpg'
        );

        $productDirector->save($productReduced);
        $this->addReference('product-reduced', $productReduced);

        /**
         * Product with variants.
         *
         * @var ProductInterface $productWithVariants
         */
        $productWithVariants = $productDirector
            ->create()
            ->setName('Product with variants')
            ->setSku('product-sku-code-variant-1')
            ->setSlug('product-with-variants')
            ->setDescription('my product with variants description')
            ->setShortDescription('my product with variants short description')
            ->addCategory($category)
            ->setPrincipalCategory($category)
            ->setManufacturer($manufacturer)
            ->setStock(10)
            ->setPrice(Money::create(1000, $currency))
            ->setHeight(40)
            ->setWidth(45)
            ->setDepth(50)
            ->setWeight(500)
            ->setEnabled(true);

        $productDirector->save($productWithVariants);
        $this->addReference('product-with-variants', $productWithVariants);

        /**
         * Root category product.
         *
         * @var ProductInterface $rootCategoryProduct
         */
        $rootCategoryProduct = $productDirector
            ->create()
            ->setName('Root category product')
            ->setSlug('root-category-product')
            ->setDescription('my product description')
            ->setShortDescription('my product short description')
            ->addCategory($rootCategory)
            ->setPrincipalCategory($rootCategory)
            ->setManufacturer($manufacturer)
            ->setStock(10)
            ->setPrice(Money::create(500, $currency))
            ->setSku('product-sku-code-3')
            ->setHeight(10)
            ->setWidth(15)
            ->setDepth(20)
            ->setWeight(100)
            ->setEnabled(true);

        $productDirector->save($rootCategoryProduct);
        $this->addReference('rootCategoryProduct', $rootCategoryProduct);
    }
860486
public function getGraphQLType(Manager $manager = null)
    {
        $type = $this->createTypeParser()->getType();
        $name = $type->name;
        if ($manager && !$this->isInternal($name)) {
            return $manager->getType($name);
        }

        return $type;
    }
156109
public function addToManager(Manager $manager)
    {
        $parser = $this->createTypeParser();
        $type = $parser->getType();
        if ($this->isInternal($type->name)) {
            return;
        }
        $manager->addType($type, $parser->getName());
    }
1046447
public function addToManager(Manager $manager)
    {
        $this->extend('onBeforeAddToManager', $manager);
        $scaffold = $this->scaffold($manager);
        if (!$manager->hasType($this->getTypeName())) {
            $manager->addType($scaffold, $this->getTypeName());
        }

        foreach ($this->operations as $op) {
            $op->addToManager($manager);
        }

        foreach ($this->nestedQueries as $scaffold) {
            $scaffold->addToManager($manager);
        }

        $this->extend('onAfterAddToManager', $manager);
    }
586110
protected function getType(Manager $manager)
    {
        // If an explicit type name has been provided, use it.
        $typeName = $this->getTypeName();
        if ($typeName && $manager->hasType($typeName)) {
            return $manager->getType($typeName);
        }

        // Fall back on a computed type name
        return StaticSchema::inst()->fetchFromManager(
            $this->dataObjectClass,
            $manager,
            StaticSchema::PREFER_UNION
        );
    }
492156
public function load(ObjectManager $manager)
    {
        $loader = new Loader();
        $loader->addFile(__DIR__.'/../../Resources/config/data/Metas.yml');
        $loader->load($manager, null, $this);
    }
282637
public function load(ObjectManager $manager)
    {
        /**
         * @var ObjectDirector $menuDirector
         */
        $menuDirector = $this->getDirector('menu');

        /**
         * Admin menu.
         */
        $menuAdmin = $menuDirector
            ->create()
            ->setCode('menu-admin')
            ->setEnabled(true)
            ->addSubnode($this->getReference('menu-node-vogue'));

        $menuDirector->save($menuAdmin);
        $this->addReference('menu-admin', $menuAdmin);

        /**
         * Front menu.
         */
        $menuFront = $menuDirector
            ->create()
            ->setCode('menu-front')
            ->setEnabled(true)
            ->addSubnode($this->getReference('menu-node-him'))
            ->addSubnode($this->getReference('menu-node-her'));

        $menuDirector->save($menuFront);
        $this->addReference('menu-front', $menuFront);
    }
322030
public function mapField(array $mapping)
    {
        $this->_validateAndCompleteFieldMapping($mapping);
        $this->assertFieldNotMapped($mapping['fieldName']);

        $this->fieldMappings[$mapping['fieldName']] = $mapping;
    }
815517
public function load(ObjectManager $manager)
    {
        /**
         * @var ObjectDirector $menuNodeDirector
         */
        $menuNodeDirector = $this->getDirector('menu_node');

        $menuNodeHim = $menuNodeDirector
            ->create()
            ->setName('him')
            ->setCode('him')
            ->setUrl('elcodi.dev/him')
            ->setActiveUrls([])
            ->setEnabled(true);

        $menuNodeHer = $menuNodeDirector
            ->create()
            ->setName('her')
            ->setCode('her')
            ->setUrl('elcodi.dev/her')
            ->setActiveUrls(
                [
                    'her_products_list_route',
                    'her_offers_list_route',
                ]
            )
            ->setEnabled(true);

        $menuNodeVogue = $menuNodeDirector
            ->create()
            ->setName('vogue')
            ->setCode('vogue')
            ->setEnabled(true)
            ->setActiveUrls([])
            ->addSubnode($menuNodeHim)
            ->addSubnode($menuNodeHer);

        $menuNodeDirector->save($menuNodeVogue);
        $this->addReference('menu-node-him', $menuNodeHim);
        $this->addReference('menu-node-her', $menuNodeHer);
        $this->addReference('menu-node-vogue', $menuNodeVogue);
    }
393827
public function convertToDocument($rawData, Manager $manager)
    {
        $types = $this->metadataCollector->getMappings($manager->getConfig()['mappings']);

        if (isset($types[$rawData['_type']])) {
            $metadata = $types[$rawData['_type']];
        } else {
            throw new \LogicException("Got document of unknown type '{$rawData['_type']}'.");
        }

        switch (true) {
            case isset($rawData['_source']):
                $rawData = array_merge($rawData, $rawData['_source']);
                break;
            case isset($rawData['fields']):
                $rawData = array_merge($rawData, $rawData['fields']);
                break;
            default:
                // Do nothing.
                break;
        }

        $object = $this->assignArrayToObject($rawData, new $metadata['namespace'](), $metadata['aliases']);

        return $object;
    }
343091
private function createGroup(ObjectManager $manager, $name, array $roles = array())
    {
        $group = new Group($name);
        foreach ($roles as $role) {
            $group->addRole($role);
        }
        $manager->persist($group);

        return $group;
    }
941481
public function destroy(Manager $manager)
    {
        $manager->delete();

        return intend([
            'url' => route('adminarea.managers.index'),
            'with' => ['warning' => trans('cortex/foundation::messages.resource_deleted', ['resource' => trans('cortex/auth::common.manager'), 'identifier' => $manager->username])],
        ]);
    }
741745
public function load(ObjectManager $manager)
    {
        $user = new User();
        $user->setFirstname('admin');
        $user->setFirstname('admin');
        $user->setUsername('admin');
        $user->setEmail('admin@test.com');
        $user->setState(1);

        $newPass = 'playground';

        $bcrypt = new Bcrypt;
        $bcrypt->setCost(14);

        $pass = $bcrypt->create($newPass);
        $user->setPassword($pass);

        $user->addRole(
            $this->getReference('admin-role') // load the stored reference
        );

        $manager->persist($user);

        $manager->flush();

        $user = new User();
        $user->setFirstname('supervisor');
        $user->setFirstname('supervisor');
        $user->setUsername('supervisor');
        $user->setEmail('supervisor@test.com');
        $user->setState(1);

        $newPass = 'playground';

        $bcrypt = new Bcrypt;
        $bcrypt->setCost(14);

        $pass = $bcrypt->create($newPass);
        $user->setPassword($pass);

        $user->addRole(
            $this->getReference('supervisor-role') // load the stored reference
        );

        $manager->persist($user);

        $manager->flush();

        $user = new User();
        $user->setFirstname('game-manager');
        $user->setFirstname('game-manager');
        $user->setUsername('gamemanager');
        $user->setEmail('game-manager@test.com');
        $user->setState(1);

        $newPass = 'playground';

        $bcrypt = new Bcrypt;
        $bcrypt->setCost(14);

        $pass = $bcrypt->create($newPass);
        $user->setPassword($pass);

        $user->addRole(
            $this->getReference('game-role') // load the stored reference
        );

        $manager->persist($user);

        $manager->flush();
    }
1117596
protected function getType(Manager $manager)
    {
        // If an explicit type name has been provided, use it.
        $typeName = $this->getTypeName();
        if ($typeName && $manager->hasType($typeName)) {
            return $manager->getType($typeName);
        }

        // Fall back on a computed type name
        $dataObjectClass = $this->getDataObjectClass();
        if ($dataObjectClass) {
            return StaticSchema::inst()->fetchFromManager(
                $this->getDataObjectClass(),
                $manager,
                StaticSchema::PREFER_SINGLE
            );
        }

        throw new InvalidArgumentException(sprintf(
            '%s must have either a typeName or dataObjectClass member defined.',
            __CLASS__
        ));
    }