Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
F
fillpdf
Manage
Activity
Members
Labels
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
drupal.org
fillpdf
Commits
84fa48e2
Commit
84fa48e2
authored
2 years ago
by
Liam Morland
Browse files
Options
Downloads
Patches
Plain Diff
Issue #3047913: Convert 'default_entity_id' column into a string
parent
7c15d171
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
fillpdf.install
+57
-0
57 additions, 0 deletions
fillpdf.install
src/Entity/FillPdfForm.php
+1
-1
1 addition, 1 deletion
src/Entity/FillPdfForm.php
with
58 additions
and
1 deletion
fillpdf.install
+
57
−
0
View file @
84fa48e2
...
...
@@ -305,3 +305,60 @@ function fillpdf_update_9501() {
// Commit transaction.
unset
(
$transaction
);
}
/**
* Convert default_entity_id to string.
*/
function
fillpdf_update_9502
()
{
// @see https://www.drupal.org/docs/drupal-apis/update-api/updating-entities-and-fields-in-drupal-8#s-updating-a-base-field-type
$database
=
\Drupal
::
database
();
$transaction
=
$database
->
startTransaction
();
$entity_type_manager
=
\Drupal
::
entityTypeManager
();
$bundle_of
=
'fillpdf_form'
;
$field_name
=
'default_entity_id'
;
$storage
=
$entity_type_manager
->
getStorage
(
$bundle_of
);
$bundle_definition
=
$entity_type_manager
->
getDefinition
(
$bundle_of
);
// Sometimes the primary key isn't 'id'. e.g. 'eid' or 'item_id'.
$id_key
=
$bundle_definition
->
getKey
(
'id'
);
// If there is no data table defined then use the base table.
$table_name
=
$storage
->
getDataTable
()
?:
$storage
->
getBaseTable
();
$definition_manager
=
\Drupal
::
entityDefinitionUpdateManager
();
// Store the existing values.
$migrated_values
=
$database
->
select
(
$table_name
)
->
fields
(
$table_name
,
[
$id_key
,
$field_name
])
->
execute
()
->
fetchAllKeyed
();
// Clear out the values.
$database
->
update
(
$table_name
)
->
fields
([
$field_name
=>
NULL
])
->
execute
();
// Uninstall the field.
$field_storage_definition
=
$definition_manager
->
getFieldStorageDefinition
(
$field_name
,
$bundle_of
);
$definition_manager
->
uninstallFieldStorageDefinition
(
$field_storage_definition
);
// Create a new field definition.
$new_field
=
BaseFieldDefinition
::
create
(
'string'
)
->
setName
(
$field_name
)
->
setProvider
(
$bundle_of
)
->
setTargetBundle
(
NULL
)
->
setTargetEntityTypeId
(
$bundle_of
);
// Install the new definition.
$definition_manager
->
installFieldStorageDefinition
(
$field_name
,
$bundle_of
,
$bundle_of
,
$new_field
);
// Restore the values.
foreach
(
$migrated_values
as
$id
=>
$value
)
{
$database
->
update
(
$table_name
)
->
fields
([
$field_name
=>
(
string
)
$value
])
->
condition
(
$id_key
,
$id
)
->
execute
();
}
// Commit transaction.
unset
(
$transaction
);
}
This diff is collapsed.
Click to expand it.
src/Entity/FillPdfForm.php
+
1
−
1
View file @
84fa48e2
...
...
@@ -110,7 +110,7 @@ class FillPdfForm extends ContentEntityBase implements FillPdfFormInterface {
$fields
[
'default_entity_type'
]
=
BaseFieldDefinition
::
create
(
'string'
);
// Form element is set up in FillPdfFormForm.
$fields
[
'default_entity_id'
]
=
BaseFieldDefinition
::
create
(
'
integer
'
);
$fields
[
'default_entity_id'
]
=
BaseFieldDefinition
::
create
(
'
string
'
);
$fields
[
'destination_path'
]
=
BaseFieldDefinition
::
create
(
'string'
)
->
setLabel
(
t
(
'Destination path'
))
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment