Commit 4e0a7a8b authored by catch's avatar catch
Browse files

Issue #3110393 by andypost, mpdonadio, Berdir, longwave: Remove @deprecated...

Issue #3110393 by andypost, mpdonadio, Berdir, longwave: Remove @deprecated views code datetime_range.module
parent 8d60ee16
......@@ -7,8 +7,6 @@
use Drupal\Core\Url;
use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\views\Views;
use Drupal\views\ViewEntityInterface;
/**
* Implements hook_help().
......@@ -29,141 +27,3 @@ function datetime_range_help($route_name, RouteMatchInterface $route_match) {
return $output;
}
}
/**
* Implements hook_ENTITY_TYPE_presave().
*
* When a view is saved using the old string or standard plugin format for
* Datetime Range filters or sorts, they will automatically be updated to
* Datetime filters or sorts. Old plugins usage must to be considered
* deprecated and must be converted before 9.0.0, when this updating layer will
* be removed.
*
* @deprecated in drupal:8.5.0 and is removed from drupal:9.0.0.
*
* @see https://www.drupal.org/node/2857691
*/
function datetime_range_view_presave(ViewEntityInterface $view) {
$config_factory = \Drupal::configFactory();
$displays = $view->get('display');
$changed = FALSE;
foreach ($displays as $display_name => &$display) {
// Update datetime_range filters.
if (isset($display['display_options']['filters'])) {
foreach ($display['display_options']['filters'] as $field_name => &$filter) {
if ($filter['plugin_id'] === 'string') {
$table_data = Views::viewsData()->get($filter['table']);
if (!$table_data) {
continue;
}
// Get field config.
$filter_views_data = $table_data[$filter['field']]['filter'];
if (!isset($filter_views_data['entity_type']) || !isset($filter_views_data['field_name'])) {
continue;
}
$field_storage_name = 'field.storage.' . $filter_views_data['entity_type'] . '.' . $filter_views_data['field_name'];
$field_configuration = $config_factory->get($field_storage_name);
if ($field_configuration->get('type') === 'daterange') {
// Set entity_type if missing.
if (!isset($filter['entity_type'])) {
$filter['entity_type'] = $filter_views_data['entity_type'];
}
// Set datetime plugin_id.
$filter['plugin_id'] = 'datetime';
// Create datetime value array.
$datetime_value = [
'min' => '',
'max' => '',
'value' => $filter['value'],
'type' => 'date',
];
// Map string operator/value to numeric equivalent.
switch ($filter['operator']) {
case '=':
case 'empty':
case 'not empty':
$operator = $filter['operator'];
break;
case '!=':
case 'not':
$operator = '!=';
break;
case 'starts':
$operator = 'regular_expression';
$datetime_value['value'] = '^' . preg_quote($datetime_value['value']);
break;
case 'ends':
$operator = 'regular_expression';
$datetime_value['value'] = preg_quote($datetime_value['value']) . '$';
break;
default:
$operator = 'regular_expression';
// Add .* to prevent blank regexes.
if (empty($datetime_value['value'])) {
$datetime_value['value'] = '.*';
}
else {
$datetime_value['value'] = preg_quote($datetime_value['value']);
}
}
// Set value and operator.
$filter['value'] = $datetime_value;
$filter['operator'] = $operator;
$changed = TRUE;
@trigger_error('Use of string filters for datetime_range fields is deprecated. Use the datetime filters instead. See https://www.drupal.org/node/2857691', E_USER_DEPRECATED);
}
}
}
}
// Update datetime_range sort handlers.
if (isset($display['display_options']['sorts'])) {
foreach ($display['display_options']['sorts'] as $field_name => &$sort) {
if ($sort['plugin_id'] === 'standard') {
$table_data = Views::viewsData()->get($sort['table']);
if (!$table_data) {
continue;
}
// Get field config.
$sort_views_data = $table_data[$sort['field']]['sort'];
if (!isset($sort_views_data['entity_type']) || !isset($sort_views_data['field_name'])) {
continue;
}
$field_storage_name = 'field.storage.' . $sort_views_data['entity_type'] . '.' . $sort_views_data['field_name'];
$field_configuration = $config_factory->get($field_storage_name);
if ($field_configuration->get('type') === 'daterange') {
// Set entity_type if missing.
if (!isset($sort['entity_type'])) {
$sort['entity_type'] = $sort_views_data['entity_type'];
}
// Set datetime plugin_id.
$sort['plugin_id'] = 'datetime';
$changed = TRUE;
@trigger_error('Use of standard sort handlers for datetime_range fields is deprecated. Use the datetime sort handlers instead. See https://www.drupal.org/node/2857691', E_USER_DEPRECATED);
}
}
}
}
}
if ($changed) {
$view->set('display', $displays);
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment