@param string      $field
@param string|null $block

@throws FieldConfigurationException

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

        if ($block === null && !isset($this->mapping['data']['fields'][$field]['fieldtype'])) {
            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];
        }

        $setting = $mapping['fieldtype'];

        return $this->em->getFieldManager()->get($setting, $mapping);
    }
325495
public function updateCMSFields(FieldList $fields)
	{
		if ($fields->fieldByName('Root.Blocks') || !$this->showBlocksFields()) {
			return;
		}

		$areas = $this->blockManager->getAreasForPageType($this->owner->ClassName);

		if ($areas && count($areas)) {
			$fields->addFieldToTab('Root', new Tab('Blocks', _t('Block.PLURALNAME', 'Blocks')));
			if (BlockManager::config()->get('block_area_preview')) {
				$fields->addFieldToTab('Root.Blocks',
						LiteralField::create('PreviewLink', $this->areasPreviewButton()));
			}

			// Blocks related directly to this Page
			$gridConfig = GridFieldConfigBlockManager::create(true, true, true, true)
				->addExisting($this->owner->class)
				//->addBulkEditing()
				// ->addComponent(new GridFieldOrderableRows()) // Comment until below TODO is complete.
				;


			// TODO it seems this sort is not being applied...
			$gridSource = $this->owner->Blocks();
				// ->sort(array(
				// 	"FIELD(SiteTree_Blocks.BlockArea, '" . implode("','", array_keys($areas)) . "')" => '',
				// 	'SiteTree_Blocks.Sort' => 'ASC',
				// 	'Name' => 'ASC'
				// ));

			$fields->addFieldToTab('Root.Blocks', GridField::create('Blocks', _t('Block.PLURALNAME', 'Blocks'), $gridSource, $gridConfig));


			// Blocks inherited from BlockSets
			if ($this->blockManager->getUseBlockSets()) {
				$inheritedBlocks = $this->getBlocksFromAppliedBlockSets(null, true);

				if ($inheritedBlocks->count()) {
					$activeInherited = $this->getBlocksFromAppliedBlockSets(null, false);

					if ($activeInherited->count()) {
						$fields->addFieldsToTab('Root.Blocks', [
							GridField::create('InheritedBlockList', _t('BlocksSiteTreeExtension.BlocksInheritedFromBlockSets', 'Blocks Inherited from Block Sets'), $activeInherited,
								GridFieldConfigBlockManager::create(false, false, false)),
							LiteralField::create('InheritedBlockListTip', "<p class='message'>"._t('BlocksSiteTreeExtension.InheritedBlocksEditLink', 'Tip: Inherited blocks can be edited in the {link_start}Block Admin area{link_end}', '', ['link_start' => '<a href="admin/block-admin">', 'link_end' => '</a>']).'<p>'),
						]);
					}

					$fields->addFieldToTab('Root.Blocks',
							ListboxField::create('DisabledBlocks', _t('BlocksSiteTreeExtension.DisableInheritedBlocks', 'Disable Inherited Blocks'),
									$inheritedBlocks->map('ID', 'Title'), null, null, true)
									->setDescription(_t('BlocksSiteTreeExtension.DisableInheritedBlocksDescription', 'Select any inherited blocks that you would not like displayed on this page.'))
					);
				} else {
					$fields->addFieldToTab('Root.Blocks',
							ReadonlyField::create('DisabledBlocksReadOnly', _t('BlocksSiteTreeExtension.DisableInheritedBlocks', 'Disable Inherited Blocks'),
									_t('BlocksSiteTreeExtension.NoInheritedBlocksToDisable','This page has no inherited blocks to disable.')));
				}

				$fields->addFieldToTab('Root.Blocks',
					CheckboxField::create('InheritBlockSets', _t('BlocksSiteTreeExtension.InheritBlocksFromBlockSets', 'Inherit Blocks from Block Sets')));
			}
		}
	}
1159408
public function getCustomField($type, $field)
    {
        if (!isset($this->customFields[$type]) ||
             !isset($this->customFields[$type][$field])) {
            return null;
        }

        return $this->customFields[$type][$field];
    }
21793
public static function factory(Localization $base, Block $source = null)
	{
		$block = null;

		switch ($base::DISCRIMINATOR) {
			case self::TEMPLATE_DISCR:
				$block = new TemplateBlock();
				break;
			case self::PAGE_DISCR:
			case self::APPLICATION_DISCR:
				$block = new PageBlock();
				break;
			default:
				throw new \LogicException("Not recognized discriminator value for entity [{$base}].");
		}

		if ($source !== null) {
			$block->setComponentClass($source->getComponentClass());
			$block->setPosition($source->getPosition());

			foreach ($source->getBlockProperties() as $blockProperty) {
				/* @var $blockProperty BlockProperty */

				$newBlockProperty = clone $blockProperty;

				$newBlockProperty->setLocalization($base);
				$newBlockProperty->setBlock($block);

				$block->getBlockProperties()
						->add($newBlockProperty);
			}
		}

		return $block;
	}
620046
public function assign($fieldname, $value = null)
    {
        if ($fieldname instanceOf Block) {
            $this->blocks[] = $fieldname;
            return $this;
        }

        if (is_array($fieldname) && !empty($fieldname)) { // bulk fields assignment
            foreach ($fieldname as $field => $val) {
                $this->fields[$field] = $val;
            }
            return $this;
        }

        if (is_string($fieldname) && $value instanceOf Image) {
            $this->images['image:' . $fieldname] = $value->getName();
            return $this;
        }

        if (is_string($fieldname) && !is_null($value)) {
            $this->fields[$fieldname] = $value;
            return $this;
        }

        throw new ContainerException('Incorrect parameters for assignment');
    }
97197
public function map($field, $context = null)
    {
        if (array_key_exists('hidden', $field)) {
            $field['hidden'] = (bool) $field['hidden'];
        } else {
            $field['hidden'] = false;
        }

        if (!array_key_exists('restrictions', $field)) {
            $field['restrictions'] = [];
        }

        return $field;
    }
140108
public function changed($field = null)
    {
        return (null === $field)
            ? $this->_changed
            : Arr::get($this->_changed, $field);
    }
940586
private static function getBlockType(array $block): int
    {
        assert(static::debugHasKnownBlockType($block));

        $type = $block[BlockSerializer::TYPE];

        return $type;
    }
250136
def _set_field_if_present(cls, block, name, value, attrs):
        """"""
        if name in block.fields:
            value = (block.fields[name]).from_string(value)
            if "none" in attrs and attrs["none"] == "true":
                setattr(block, name, None)
            else:
                setattr(block, name, value)
        else:
            logging.warning("XBlock %s does not contain field %s", type(block), name)
172774
public function changeType(Model\BlockInterface $block, $type, array $data = [])
    {
        if ($type === $block->getType()) {
            return;
        }

        if ($block->isNamed()) {
            throw new InvalidOperationException(
                "The type of this block can't be changed."
            );
        }

        // Plugin removal
        $this->editor
            ->getBlockPlugin($block->getType())
            ->remove($block);

        // Sets the new type
        $block->setType($type);

        // Plugin creation
        $this->editor
            ->getBlockPlugin($block->getType())
            ->create($block, $data);
    }
684982
public function getField(string $field)
    {
        if (isset($this->_record[$field]))
            return $this->_record[$field];
        return null;
    }
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);
    }
236653
public function field($field) : FormFieldBindingDefiner
    {
        if ($field instanceof FieldBuilderBase) {
            $field = $field->build();
        }

        InvalidArgumentException::verifyInstanceOf(__METHOD__, 'field', $field, IField::class);

        return new FormFieldBindingDefiner($this->class, $field);
    }
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);
    }
679843
public function includeBlockabale(Block $block)
    {
        $blockable = $block->blockable;
        if (!empty($blockable)) {
            $entityClassName  = (new ReflectionClass($blockable))->getShortName();
            $transformerClass = 'Gzero\\Api\\Transformer\\' . $entityClassName . 'Transformer';
            return $this->item($blockable, new $transformerClass());
        }
        return null;
    }
626257
private Object getValue(FieldType field, byte[] block)
   {
      Object result = null;

      switch (block[0])
      {
         case 0x07: // Field
         {
            result = getFieldType(block);
            break;
         }

         case 0x01: // Constant value
         {
            result = getConstantValue(field, block);
            break;
         }

         case 0x00: // Prompt
         {
            result = getPromptValue(field, block);
            break;
         }
      }

      return result;
   }