@param string $field
@param null   $block

@throws FieldConfigurationException

@return mixed
334084
protected function getFieldTypeName($field, $block = null)
    {
        if ($block !== null && !isset($this->mapping['data']['fields'][$block]['fields'][$field]['type'])) {
            throw new FieldConfigurationException('Invalid repeating field configuration for ' . $field);
        }

        if ($block === null && !isset($this->mapping['data']['fields'][$field]['type'])) {
            throw new FieldConfigurationException('Invalid repeating field configuration for ' . $field);
        }

        if ($block !== null) {
            $mapping = $this->mapping['data']['fields'][$block]['fields'][$field];
        } else {
            $mapping = $this->mapping['data']['fields'][$field];
        }

        return $mapping['type'];
    }
472686
final public function getRowFieldValue($field)
    {

        //If value exists;
        if (array_key_exists($field, $this->schema)) {
            return $this->schema[$field]->Value;
        }
        return null;
    }
1250908
public function errors(string $field = null)
    {
        if ($field !== null) {
            return $this->_errors[$field] ?? false;
        }

        return $this->_errors;
    }
274116
public function getField($field)
    {
        if (!$this->isFieldSupported($field)) {
            return null;
        }

        if (!$this->hasLoadedField($field)) {
            $loaderData = $this->getLoaderData($field);
            if ($normalizer = $this->normalizersMap->getNormalizerForField($field)) {
                switch ($normalizer[ 'type' ]) {
                    case NormalizersMap::TYPE_METHOD:
                        $this->fields[ $field ] =
                            $this->{sprintf('%sNormalizer', $normalizer[ 'method' ])}($loaderData);
                        break;

                    case NormalizersMap::TYPE_ARRAY_PATH:
                        $this->fields[ $field ] =
                            ArrayUtils::getNested($loaderData, $normalizer[ 'path' ], $normalizer[ 'defaultValue' ]);
                        break;

                    case NormalizersMap::TYPE_PREFILLED_VALUE:
                        $this->fields[ $field ] = $normalizer[ 'value' ];
                        break;

                    default:
                        throw new GenericException("Unknown normalizer type \"{$normalizer['type']}\"");
                }

                switch ($field) {
                    case self::FIELD_WEBSITES:
                    case self::FIELD_EXTRA:
                        if ($this->fields[ $field ]) {
                            $this->fields[ $field ] = (array) $this->fields[ $field ];
                        } else {
                            $this->fields[ $field ] = [];
                        }
                        break;
                }
            } // Don't need to be normalized
            else {
                $this->fields[ $field ] = $loaderData;
            }
        }

        return parent::getField($field);
    }
1200387
public static function config($config_block)
    {
        if (!empty(self::$config)) {
            return self::$config[$config_block];
        }

        $config_file = "database.php";
        $path = __DIR__ . "/../config/" .$config_file;

        $env =  (getenv('APPLICATION_ENV') ? getenv('APPLICATION_ENV') : '');

        if ($config_block == "default" && $env) {
            $config_block = $env;
        }

        if (file_exists($path)) {
            $config = (include $path);
            if (isset($config[$config_block])) {
                return $config[$config_block];
            } else {
                throw new \Exception("Database config section '{$config_block}' not exists.");
            }

            return $config['default'];
        } else {
            throw new \Exception("Database config not found.");
        }

    }
664967
public function getBlockVariables($field, $entity)
    {
        $defaults = parent::getBlockVariables($field, $entity);

        $data = $defaults['value'];

        if ($data instanceof \Traversable) {
            $dataArray = [];
            foreach ($data as $element) {
                $dataArray[] = $element->__toString();
            }

            $string = implode(', ', $dataArray);
        } else if (is_array($data)) {
            $string = implode(', ', $data);
        } else {
            $string = 'Unsupported.';
        }

        return [
            'value' => $string,
            'truncate' => $field->getOption('truncate', 80),
        ] + $defaults;
    }
435232
public function getField($field)
    {
        // Skip invalid fields
        $fields = $this->compositeDatabaseFields();
        if (!isset($fields[$field])) {
            return null;
        }

        // Check bound object
        if ($this->record instanceof DataObject) {
            $key = $this->getName() . $field;
            return $this->record->getField($key);
        }

        // Check local record
        if (isset($this->record[$field])) {
            return $this->record[$field];
        }
        return null;
    }
46047
public function makeXpathForBlock( $block = null )
    {
        if ( empty( $block ) )
        {
            return null;
        }

        $parameter = ( isset( $this->mainAttributes[strtolower( $block )] ) ) ?
            $this->mainAttributes[strtolower( $block )] :
            NULL;

        Assertion::assertNotNull( $parameter, "Element {$block} is not defined" );

        $xpath = $this->mainAttributes[strtolower( $block )];
        // check if value is a composed array
        if ( is_array( $xpath ) )
        {
            // if there is an xpath defined look no more!
            if ( isset( $xpath['xpath'] ) )
            {
                return $xpath['xpath'];
            }

            $nuXpath = "";
            // verify if there is a tag
            if ( isset( $xpath['tag'] ) )
            {
                if ( strpos( $xpath['tag'], "/" ) === 0 || strpos( $xpath['tag'], "(" ) === 0 )
                {
                    $nuXpath = $xpath['tag'];
                }
                else
                {
                    $nuXpath = "//" . $xpath['tag'];
                }

                unset( $xpath['tag'] );
            }
            else
            {
                $nuXpath = "//*";
            }

            foreach ( $xpath as $key => $value )
            {
                switch ( $key )
                {
                    case "text":
                        $att = "text()";
                        break;
                    default:
                        $att = "@$key";
                }
                $nuXpath .= "[contains($att, {$this->getXpath()->literal( $value )})]";
            }

            return $nuXpath;
        }

        //  if the string is an Xpath
        if ( strpos( $xpath, "/" ) === 0 || strpos( $xpath, "(" ) === 0 )
        {
            return $xpath;
        }

        // if xpath is an simple tag
        return "//$xpath";
    }
309509
protected function getFromCache(Block $block, Language $language)
    {
        if ($block->is_cacheable) {
            return cache()->tags(['blocks'])->get('blocks:cache:' . $block->id . ':' . $language->code, null);
        }
        return null;
    }
172658
public function getBlockVariables($field, $entity)
    {
        $defaults = parent::getBlockVariables($field, $entity);

        $base_path = $field->getOption('base_path', 'uploads');
        $image = $defaults['value'];

        $value = null;
        if (!empty($image)) {
            $value = $base_path . '/' . $image;
        }

        return [
            'value' => $value,
        ] + $defaults;
    }
1361821
protected function getFieldType($field)
    {
        if (!isset($this->mapping['data']['fields'][$field]['fieldtype'])) {
            throw new FieldConfigurationException('Invalid repeating field configuration for ' . $field);
        }
        $mapping = $this->mapping['data']['fields'][$field];
        $setting = $mapping['fieldtype'];

        return $this->em->getFieldManager()->get($setting, $mapping);
    }
1118734
public function renderBlock(AbstractBlock $block)
    {
        $renderer = $this->getBlockRendererForClass(get_class($block));
        if (!$renderer) {
            throw new RuntimeException(
                sprintf('Unable to find corresponding renderer for block type: "%s"', get_class($block))
            );
        }

        return $renderer->render($block, $this);
    }
967051
public function getField($field)
	{
		$result = $this->client->get("fields/{$field}");
		return $result ? new Resources\Field($this, $result) : null;
	}
1208960
public function newBlockUpdateStruct(string $locale, ?Block $block = null): BlockUpdateStruct
    {
        $blockUpdateStruct = new BlockUpdateStruct();
        $blockUpdateStruct->locale = $locale;

        if (!$block instanceof Block) {
            return $blockUpdateStruct;
        }

        $blockUpdateStruct->viewType = $block->getViewType();
        $blockUpdateStruct->itemViewType = $block->getItemViewType();
        $blockUpdateStruct->name = $block->getName();
        $blockUpdateStruct->alwaysAvailable = $block->isAlwaysAvailable();
        $blockUpdateStruct->fillParametersFromBlock($block);

        $this->configStructBuilder->buildConfigUpdateStructs($block, $blockUpdateStruct);

        return $blockUpdateStruct;
    }
992014
public function setField($field = null)
    {
        $this->field = null;

        if (!$field = $this->internalResolveField($field)) {
            $this->field = $this->fieldId = null;
        } else {
            $this->fieldId = $field->id;
            $this->field = $field;
        }

        return $this;
    }
567011
public function updateBlock(Block $block): void
    {
        $query = $this->connection->createQueryBuilder();
        $query
            ->update('ngbm_block')
            ->set('layout_id', ':layout_id')
            ->set('depth', ':depth')
            ->set('path', ':path')
            ->set('parent_id', ':parent_id')
            ->set('placeholder', ':placeholder')
            ->set('position', ':position')
            ->set('definition_identifier', ':definition_identifier')
            ->set('view_type', ':view_type')
            ->set('item_view_type', ':item_view_type')
            ->set('name', ':name')
            ->set('translatable', ':translatable')
            ->set('main_locale', ':main_locale')
            ->set('always_available', ':always_available')
            ->set('config', ':config')
            ->where(
                $query->expr()->eq('id', ':id')
            )
            ->setParameter('id', $block->id, Type::INTEGER)
            ->setParameter('layout_id', $block->layoutId, Type::INTEGER)
            ->setParameter('depth', $block->depth, Type::STRING)
            ->setParameter('path', $block->path, Type::STRING)
            ->setParameter('parent_id', $block->parentId, Type::INTEGER)
            ->setParameter('placeholder', $block->placeholder, Type::STRING)
            ->setParameter('position', $block->position, Type::INTEGER)
            ->setParameter('definition_identifier', $block->definitionIdentifier, Type::STRING)
            ->setParameter('view_type', $block->viewType, Type::STRING)
            ->setParameter('item_view_type', $block->itemViewType, Type::STRING)
            ->setParameter('name', $block->name, Type::STRING)
            ->setParameter('translatable', $block->isTranslatable, Type::BOOLEAN)
            ->setParameter('main_locale', $block->mainLocale, Type::STRING)
            ->setParameter('always_available', $block->alwaysAvailable, Type::BOOLEAN)
            ->setParameter('config', $block->config, Type::JSON_ARRAY);

        $this->applyStatusCondition($query, $block->status);

        $query->execute();
    }
1275317
private function loadBlockDefaults(BlockInterface $block)
    {
        $service = $this->blockManager->get($block);

        $resolver = new OptionsResolver();
        // use new interface method whenever possible
        // NEXT_MAJOR: Remove this check and legacy setDefaultSettings method call
        if (method_exists($service, 'configureSettings')) {
            $service->configureSettings($resolver);
        } else {
            $service->setDefaultSettings($resolver);
        }

        try {
            $block->setSettings($resolver->resolve($block->getSettings()));
        } catch (InvalidOptionsException $e) {
            // @TODO : add a logging error or a flash message
        }

        $service->load($block);

        return $block;
    }