We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
When saving a FieldLayout that has native fields defined like the example at https://craftcms.com/docs/4.x/extend/element-types.html#native-layout-elements The type attribute does not get saved because it gets overridden by the class name.
The below example with a number type
// Plugin Event::on( FieldLayout::class, FieldLayout::EVENT_DEFINE_NATIVE_FIELDS, function(DefineFieldLayoutFieldsEvent $event) { $fieldLayout = $event->sender; switch ($fieldLayout->type) { case ResultElement::class: $event->fields[] = [ 'label' => self::t('Priority'), 'class' => \craft\fieldlayoutelements\TextField::class, 'attribute' => 'priority', 'type' => 'number', 'step' => 1, 'min' => 0, ]; break; } } ); $service = $this->getResults(); $projectConfig->onAdd(Results::PROJECT_CONFIG_PATH . '.fieldLayout', [$service, 'handleChangedFieldLayout']) ->onUpdate(Results::PROJECT_CONFIG_PATH . '.fieldLayout', [$service, 'handleChangedFieldLayout']) ->onRemove(Results::PROJECT_CONFIG_PATH . '.fieldLayout', [$service, 'handleDeletedFieldLayout']); // Controller public function actionSave(): ?Response { $this->requirePostRequest(); $fieldLayout = Craft::$app->getFields()->assembleLayoutFromPost(); if (!$fieldLayout->validate()) { Craft::info('Field layout not saved due to validation error.', __METHOD__); Craft::$app->getUrlManager()->setRouteParams([ 'fieldLayout' => $fieldLayout, ]); $this->setFailFlash(Search::t('Couldn’t save result fields.')); return null; } $currentFieldLayout = Craft::$app->getProjectConfig()->get( Results::PROJECT_CONFIG_PATH . '.fieldLayout' ); if ($currentFieldLayout) { $uid = ArrayHelper::firstKey($currentFieldLayout); } else { $uid = StringHelper::UUID(); } Craft::$app->getProjectConfig()->set( Results::PROJECT_CONFIG_PATH . '.fieldLayout', [$uid => $fieldLayout->getConfig()] ); $this->setSuccessFlash(Search::t('Result fields saved.')); return $this->redirectToPostedUrl(); } // Service public function handleChangedFieldLayout(ConfigEvent $event): void { $data = $event->newValue; ProjectConfigHelper::ensureAllFieldsProcessed(); $fieldsService = Craft::$app->getFields(); if (empty($data) || empty(reset($data))) { // Delete the field layout $fieldsService->deleteLayoutsByType(ResultElement::class); return; } // Save the field layout $layout = FieldLayout::createFromConfig(reset($data)); $layout->id = $fieldsService->getLayoutByType(ResultElement::class)->id; $layout->type = ResultElement::class; $layout->uid = key($data); $fieldsService->saveLayout($layout, false); }
The field should display as type="number".
The field displays as type="text"
4.5.11.1
No response
The text was updated successfully, but these errors were encountered:
Hi, thanks for reporting. I raised a PR to adjust this.
Sorry, something went wrong.
Craft 4.5.12 is out with a new PlainText::$inputType property, and $type is now deprecated.
PlainText::$inputType
$type
i-just
No branches or pull requests
What happened?
Description
When saving a FieldLayout that has native fields defined like the example at https://craftcms.com/docs/4.x/extend/element-types.html#native-layout-elements The type attribute does not get saved because it gets overridden by the class name.
The below example with a number type
Expected behavior
The field should display as type="number".
Actual behavior
The field displays as type="text"
Craft CMS version
4.5.11.1
PHP version
No response
Operating system and version
No response
Database type and version
No response
Image driver and version
No response
Installed plugins and versions
The text was updated successfully, but these errors were encountered: