Skip to content
Snippets Groups Projects

Issue #3455824: Do not override default settings copied from existing field

Merged Jacob Rockowitz requested to merge issue/schemadotorg-3455824:3455824-do-not-override into 1.0.x
1 file
+ 59
54
Compare changes
  • Side-by-side
  • Inline
@@ -424,70 +424,75 @@ class SchemaDotOrgEntityTypeBuilder implements SchemaDotOrgEntityTypeBuilderInte
$field_type = $field_storage_values['type'];
switch ($field_type) {
case 'boolean':
$field_values['settings'] = [
'on_label' => $this->t('Yes'),
'off_label' => $this->t('No'),
];
if (!isset($field_values['settings']['on_label'])
&& !isset($field_values['settings']['off_label'])) {
$field_values['settings']['on_label'] = $this->t('Yes');
$field_values['settings']['off_label'] = $this->t('No');
}
break;
case 'datetime':
switch ($schema_property) {
case 'expires':
case 'dateCreated':
case 'dateDeleted':
case 'dateIssued':
case 'dateModified':
case 'datePosted':
case 'datePublished':
case 'dateVehicleFirstRegistered':
case 'dissolutionDate':
case 'paymentDueDate':
case 'validFrom':
case 'validThrough':
$is_date = TRUE;
break;
case 'startDate':
case 'endDate':
$is_date = (!$this->schemaTypeManager->isSubTypeOf($schema_type, [
'Event',
'Schedule',
]));
break;
default:
$range_includes = $this->schemaTypeManager->getPropertyRangeIncludes($schema_property);
$is_date = (in_array('Date', $range_includes) && !in_array('DateTime', $range_includes));
break;
if (!isset($field_storage_values['settings']['datetime_type'])) {
switch ($schema_property) {
case 'expires':
case 'dateCreated':
case 'dateDeleted':
case 'dateIssued':
case 'dateModified':
case 'datePosted':
case 'datePublished':
case 'dateVehicleFirstRegistered':
case 'dissolutionDate':
case 'paymentDueDate':
case 'validFrom':
case 'validThrough':
$is_date = TRUE;
break;
case 'startDate':
case 'endDate':
$is_date = (!$this->schemaTypeManager->isSubTypeOf($schema_type, [
'Event',
'Schedule',
]));
break;
default:
$range_includes = $this->schemaTypeManager->getPropertyRangeIncludes($schema_property);
$is_date = (in_array('Date', $range_includes) && !in_array('DateTime', $range_includes));
break;
}
$field_storage_values['settings']['datetime_type'] = $is_date ? 'date' : 'datetime';
}
$field_storage_values['settings']['datetime_type'] = $is_date ? 'date' : 'datetime';
break;
case 'entity_reference':
case 'entity_reference_revisions':
$target_type = $field_storage_values['settings']['target_type'] ?? 'node';
$range_includes = $this->getMappingStorage()
->getSchemaPropertyRangeIncludes($schema_type, $schema_property)
?: ['Thing'];
// Make sure that the ranges includes only includes Things
// and not DataTypes or Enumerations.
foreach ($range_includes as $range_include_type) {
if (!$this->schemaTypeManager->isThing($range_include_type)) {
unset($range_includes[$range_include_type]);
if (!isset($field_values['settings']['handler_settings'])) {
$target_type = $field_storage_values['settings']['target_type'] ?? 'node';
$range_includes = $this->getMappingStorage()
->getSchemaPropertyRangeIncludes($schema_type, $schema_property)
?: ['Thing'];
// Make sure that the ranges includes only includes Things
// and not DataTypes or Enumerations.
foreach ($range_includes as $range_include_type) {
if (!$this->schemaTypeManager->isThing($range_include_type)) {
unset($range_includes[$range_include_type]);
}
}
}
$handler_settings = [];
$handler_settings['target_type'] = $target_type;
$handler_settings['schema_types'] = $range_includes;
$handler_settings['excluded_schema_types'] = [];
$handler_settings['ignore_additional_mappings'] = FALSE;
$handler_settings = [];
$handler_settings['target_type'] = $target_type;
$handler_settings['schema_types'] = $range_includes;
$handler_settings['excluded_schema_types'] = [];
$handler_settings['ignore_additional_mappings'] = FALSE;
$field_values['settings'] = [
'handler' => 'schemadotorg:' . $target_type,
'handler_settings' => $handler_settings,
];
$field_values['settings'] = [
'handler' => 'schemadotorg:' . $target_type,
'handler_settings' => $handler_settings,
];
}
break;
case 'email':
@@ -497,7 +502,7 @@ class SchemaDotOrgEntityTypeBuilder implements SchemaDotOrgEntityTypeBuilderInte
}
/**
* Default default field settings.
* Default field settings.
*
* @param string $schema_type
* The Schema.org type.
Loading