Pre set data.

@param BlockEvent $event

@throws UnexpectedTypeException
978919
public function preSetData(BlockEvent $event)
    {
        $block = $event->getBlock();
        $data = $event->getData();

        if (null === $data) {
            $data = [];
        }

        if (!\is_array($data) && !($data instanceof \Traversable && $data instanceof \ArrayAccess)) {
            throw new UnexpectedTypeException($data, 'array or (\Traversable and \ArrayAccess)');
        }

        // First remove all rows
        foreach ($block as $name => $child) {
            $block->remove($name);
        }

        // Then add all rows again in the correct order
        foreach ($data as $name => $value) {
            $block->add($name, $this->type, array_replace([
                    'property_path' => '['.$name.']',
            ], $this->options));
        }
    }
44593
function(evt) {
			var type = evt.type;
			this._dispatchEvent("pre" + type, evt); //$NON-NLS-0$
			this._dispatchEvent(type, evt);
			this._dispatchEvent("post" + type, evt); //$NON-NLS-0$
		}
209686
public function handleChangedBlockType(ConfigEvent $event)
    {
        if ($this->ignoreProjectConfigChanges) {
            return;
        }

        $blockTypeUid = $event->tokenMatches[0];
        $data = $event->newValue;
        $previousData = $event->oldValue;

        // Make sure the field has been synced
        $fieldId = Db::idByUid(Table::FIELDS, $data['field']);
        if ($fieldId === null) {
            Craft::$app->getProjectConfig()->defer($event, [$this, __FUNCTION__]);
            return;
        }

        $fieldsService = Craft::$app->getFields();
        $contentService = Craft::$app->getContent();

        $transaction = Craft::$app->getDb()->beginTransaction();

        try {
            // Store the current contexts.
            $originalContentTable = $contentService->contentTable;
            $originalFieldContext = $contentService->fieldContext;
            $originalFieldColumnPrefix = $contentService->fieldColumnPrefix;
            $originalOldFieldColumnPrefix = $fieldsService->oldFieldColumnPrefix;

            // Get the block type record
            $blockTypeRecord = $this->_getBlockTypeRecord($blockTypeUid);

            // Set the basic info on the new block type record
            $blockTypeRecord->fieldId = $fieldId;
            $blockTypeRecord->uid = $blockTypeUid;

            // Make sure that alterations, if any, occur in the correct context.
            $contentService->fieldContext = 'superTableBlockType:' . $blockTypeUid;
            $contentService->fieldColumnPrefix = 'field_';

            /** @var SuperTableField $superTableField */
            $superTableField = $fieldsService->getFieldById($blockTypeRecord->fieldId);
            $contentService->contentTable = $superTableField->contentTable;
            $fieldsService->oldFieldColumnPrefix = 'field_';

            $oldFields = $previousData['fields'] ?? [];
            $newFields = $data['fields'] ?? [];

            // Remove fields that this block type no longer has
            foreach ($oldFields as $fieldUid => $fieldData) {
                if (!array_key_exists($fieldUid, $newFields)) {
                    $fieldsService->applyFieldDelete($fieldUid);
                }
            }

            // (Re)save all the fields that now exist for this block.
            foreach ($newFields as $fieldUid => $fieldData) {
                $fieldsService->applyFieldSave($fieldUid, $fieldData, 'superTableBlockType:' . $blockTypeUid);
            }

            // Refresh the schema cache
            Craft::$app->getDb()->getSchema()->refresh();

            $contentService->fieldContext = $originalFieldContext;
            $contentService->fieldColumnPrefix = $originalFieldColumnPrefix;
            $contentService->contentTable = $originalContentTable;
            $fieldsService->oldFieldColumnPrefix = $originalOldFieldColumnPrefix;

            if (!empty($data['fieldLayouts'])) {
                // Save the field layout
                $layout = FieldLayout::createFromConfig(reset($data['fieldLayouts']));
                $layout->id = $blockTypeRecord->fieldLayoutId;
                $layout->type = SuperTableBlockElement::class;
                $layout->uid = key($data['fieldLayouts']);

                $fieldsService->saveLayout($layout);
                $blockTypeRecord->fieldLayoutId = $layout->id;
            } else if ($blockTypeRecord->fieldLayoutId) {
                // Delete the field layout
                $fieldsService->deleteLayoutById($blockTypeRecord->fieldLayoutId);
                $blockTypeRecord->fieldLayoutId = null;
            }

            // Save it
            $blockTypeRecord->save(false);
            $transaction->commit();
        } catch (\Throwable $e) {
            $transaction->rollBack();
            throw $e;
        }

        // Clear caches
        unset(
            $this->_blockTypesById[$blockTypeRecord->id],
            $this->_blockTypesByFieldId[$blockTypeRecord->fieldId]
        );
        $this->_fetchedAllBlockTypesForFieldId[$blockTypeRecord->fieldId] = false;
    }
1245293
public function beforeFilter($event)
    {
        $this->setController($event->subject());

        if ($this->Controller->Manager->prefix('admin')) {
            if (method_exists($this->Controller, 'initPostTypes')) {
                $this->Controller->initPostTypes($event);
            }
        }
    }
1032969
public function onPreSetData(FormEvent $event)
    {
        /** @var CustomUrlAddData $data */
        $data = $event->getData();
        $location = $data->getLocation();
        if (null === $location) {
            return;
        }
        $contentInfo = $location->getContentInfo();
        $versionInfo = $this->contentService->loadVersionInfo($contentInfo);
        $contentLanguages = $versionInfo->languageCodes;

        $form = $event->getForm();

        $form->add(
            'language',
            ChoiceType::class,
            [
                'multiple' => false,
                'choice_loader' => new CallbackChoiceLoader($this->getCallableFilter($contentLanguages)),
                'choice_value' => 'languageCode',
                'choice_label' => 'name',
            ]
        );
    }
351528
public function onPreContentView(PreContentViewEvent $event): void
    {
        $currentRequest = $this->requestStack->getCurrentRequest();
        if (!$currentRequest instanceof Request) {
            return;
        }

        $viewType = $currentRequest->attributes->get('viewType');

        $event->getContentView()->addParameters(
            [
                'view_type' => !empty($viewType) ? $viewType : '',
            ]
        );
    }
837541
private function initTypes()
    {
        $this->types = [];

        foreach ($this->loadTypes() as $type) {
            if (!$type instanceof BlockTypeInterface) {
                throw new Exception\UnexpectedTypeException(
                    $type,
                    'Oro\Component\Layout\BlockTypeInterface'
                );
            }

            $this->types[$type->getName()] = $type;
        }
    }
472019
public function beforeRender(Event $event)
    {
        if (!array_key_exists('_serialize', $this->viewVars) &&
            in_array($this->response->type(), ['application/json', 'application/xml'])
        ) {
            $this->set('_serialize', true);
        }
    }
679531
public function onDataReady(DataEvent $event)
    {
         
        $data  = array();
       
        foreach ($event->getData() as $key => $row){
            foreach ($row as $field => $value){
                
                if($value instanceof \DateTime){
                    $value->setTimezone(new \DateTimeZone($this->timezone));
                }
                
                $data[$key][$field] = $value;
            }
        }
        
        $event->setData($data);
    }
513289
public function preCreate(CreateEvent $event)
    {
        /** @var Group $role */
        $object = $event->getObject();
        $user = $this->tokenStorage->getToken()->getUser();

        if ($user instanceof User) {
            $object->setUser($user);
        } else {
            $object->setUser($this->userManager->getDefaultClarolineUser());
        }
    }
1229346
public function onAfterWrite()
    {
        parent::onAfterWrite();
        foreach ($this->Preset()->Blocks() as $Preset) {
            $ClassName = $Preset->ObjectClassName;
            // Find existing relationship
            $Block = $this->Blocks()->find('PresetID', $Preset->ID);
            // Find existing dataobject if relationship doesn't exist and shares it instance
            if (!$Block && $Preset->Instance == 'shared') {
                $Block = DataObject::get_one(
                    $ClassName,
                    array(
                        'PresetID' => $Preset->ID
                    )
                );
            }
            // Create new dataobject if nothing else exists
            if (!$Block) {
                $Block = $ClassName::create();
            }
            $Block->PresetID = $Preset->ID;
            $Block->forceChange()->write();
            $this->Blocks()->add(
                $Block,
                array(
                    'Sort' => $Preset->Sort,
                    'Display' => true
                )
            );
        }
    }
447044
public function onPreDeserialize(PreDeserializeEvent $event)
    {
        $class = $event->getType()['name'];

        if (!class_exists($class)) {
            return; // skip custom JMS types
        }

        $data   = $event->getData();
        $object = new \ReflectionClass($class);

        $discriminator = $this->reader->getClassAnnotation($object, Discriminator::class);

        if ($discriminator) {
            $event->setType($discriminator->getClass($data));
        }
    }
1318885
protected function ensureInitialized($blockType)
    {
        if ($blockType instanceof BlockTypeInterface) {
            $name = $blockType->getName();
            $type = $blockType;
        } else {
            $name = $blockType;
            $type = null;
        }

        if (!isset($this->types[$name])) {
            if (!$type) {
                $type = $this->registry->getType($name);
            }

            $types      = [$type];
            $typeName   = $type->getName();
            $names      = [$typeName];
            $nameMap    = [$typeName => true];
            $parentName = $type->getParent();
            while ($parentName) {
                if (isset($this->types[$parentName])) {
                    // use data from already loaded parent type
                    $types   = array_merge($this->types[$parentName], array_reverse($types));
                    $names   = array_merge($this->names[$parentName], array_reverse($names));
                    $nameMap = array_merge($nameMap, $this->nameMap[$parentName]);
                    break;
                } else {
                    $type     = $this->registry->getType($parentName);
                    $typeName = $type->getName();

                    $types[]            = $type;
                    $names[]            = $typeName;
                    $nameMap[$typeName] = true;

                    $parentName = $type->getParent();
                }
            }

            if (null === $parentName) {
                $types = array_reverse($types);
                $names = array_reverse($names);
            }

            $this->types[$name]   = $types;
            $this->names[$name]   = $names;
            $this->nameMap[$name] = $nameMap;

            // initialise all parent types if them are not initialized yet
            $typeNames = array_keys($nameMap);
            $offset    = 0;
            while (false !== ($typeName = next($typeNames))) {
                if (isset($this->nameMap[$typeName])) {
                    break;
                }

                $offset++;
                $this->types[$typeName]   = array_slice($types, 0, -$offset);
                $this->names[$typeName]   = array_slice($names, 0, -$offset);
                $this->nameMap[$typeName] = array_slice($nameMap, $offset);
            }
        }

        return $name;
    }
1030659
public static function setDataTypes(array $types) : void
    {
        // Datatypes key validation
        foreach ($types as $key => $value) {
            if (!preg_match('/^[A-Za-z0-9-_]+$/', $key)) {
                throw new \UnexpectedValueException("<b>$key</b> is not a valid datatype key", 1);

            } elseif (!is_string($value)) {
                throw new \LogicException("<b>$key</b> must have a string value", 1);
            }
        }

        // Put keys between brackets
        self::$datatypes = array_combine(
            array_map(function ($t) {
                return '/\{' . $t . '\}/';
            }, array_keys($types)),
            $types
        );
    }
658837
public function onSubmit(FormEvent $event)
    {
        $form = $event->getForm();
        $data = $event->getData();

        if (null === $data) {
            $data = array();
        }

        if (!is_array($data) && !($data instanceof \Traversable && $data instanceof \ArrayAccess)) {
            throw new UnexpectedTypeException($data, 'array or (\Traversable and \ArrayAccess)');
        }

        // The data mapper only adds, but does not remove items, so do this here
        $toDelete = array();

        foreach ($data as $name => $child) {
            if (null === $child || (
                $form->get($name)->has('__to_remove') &&
                true === $form->get($name)->get('__to_remove')->getData()
            )) {
                $toDelete[] = $name;
            }
        }

        foreach ($toDelete as $name) {
            unset($data[$name]);
        }

        if ($data instanceof \Doctrine\Common\Collections\Collection) {
            $event->setData($data->getValues());
        } else {
            $event->setData($data);
        }
    }
537556
public function handleDeletedBlockType(ConfigEvent $event)
    {
        if ($this->ignoreProjectConfigChanges) {
            return;
        }

        $blockTypeUid = $event->tokenMatches[0];
        $blockTypeRecord = $this->_getBlockTypeRecord($blockTypeUid);

        if (!$blockTypeRecord->id) {
            return;
        }

        $db = Craft::$app->getDb();
        $transaction = $db->beginTransaction();

        try {
            $blockType = $this->getBlockTypeById($blockTypeRecord->id);

            if (!$blockType) {
                return;
            }

            // First delete the blocks of this type
            foreach (Craft::$app->getSites()->getAllSiteIds() as $siteId) {
                $blocks = SuperTableBlockElement::find()
                    ->siteId($siteId)
                    ->typeId($blockType->id)
                    ->all();

                foreach ($blocks as $block) {
                    Craft::$app->getElements()->deleteElement($block);
                }
            }

            // Set the new contentTable
            $contentService = Craft::$app->getContent();
            $fieldsService = Craft::$app->getFields();
            $originalContentTable = $contentService->contentTable;

            /** @var SuperTableField $superTableField */
            $superTableField = $fieldsService->getFieldById($blockType->fieldId);
            $contentService->contentTable = $superTableField->contentTable;

            // Set the new fieldColumnPrefix
            $originalFieldColumnPrefix = Craft::$app->getContent()->fieldColumnPrefix;
            Craft::$app->getContent()->fieldColumnPrefix = 'field_';

            // Now delete the block type fields
            foreach ($blockType->getFields() as $field) {
                Craft::$app->getFields()->deleteField($field);
            }

            // Restore the contentTable and the fieldColumnPrefix to original values.
            Craft::$app->getContent()->fieldColumnPrefix = $originalFieldColumnPrefix;
            $contentService->contentTable = $originalContentTable;

            // Delete the field layout
            $fieldLayoutId = (new Query())
                ->select(['fieldLayoutId'])
                ->from(['{{%supertableblocktypes}}'])
                ->where(['id' => $blockTypeRecord->id])
                ->scalar();

            // Delete the field layout
            Craft::$app->getFields()->deleteLayoutById($fieldLayoutId);

            // Finally delete the actual block type
            $db->createCommand()
                ->delete('{{%supertableblocktypes}}', ['id' => $blockTypeRecord->id])
                ->execute();

            $transaction->commit();
        } catch (\Throwable $e) {
            $transaction->rollBack();
            throw $e;
        }

        // Clear caches
        unset(
            $this->_blockTypesById[$blockTypeRecord->id],
            $this->_blockTypesByFieldId[$blockTypeRecord->fieldId],
            $this->_blockTypeRecordsById[$blockTypeRecord->id]
        );
        $this->_fetchedAllBlockTypesForFieldId[$blockTypeRecord->fieldId] = false;
    }
1030164
public function postSetData(FormEvent $event)
    {
        if ($event->getForm()->isRoot()) {
            // Collect basic information about each form
            $this->dataCollector->collectConfiguration($event->getForm());

            // Collect the default data
            $this->dataCollector->collectDefaultData($event->getForm());
        }
    }