Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
project
drupal
Commits
e3d6b873
Commit
e3d6b873
authored
Aug 11, 2012
by
Tim Plunkett
Browse files
Remove procedural code from plugins.
parent
0bd39a76
Changes
4
Hide whitespace changes
Inline
Side-by-side
lib/Drupal/views/Plugin/views/field/Custom.php
View file @
e3d6b873
...
...
@@ -49,15 +49,3 @@ function render($values) {
return
$this
->
options
[
'alter'
][
'text'
];
}
}
/**
* Prerender function to move the textarea to the top.
*/
function
views_handler_field_custom_pre_render_move_text
(
$form
)
{
$form
[
'text'
]
=
$form
[
'alter'
][
'text'
];
$form
[
'help'
]
=
$form
[
'alter'
][
'help'
];
unset
(
$form
[
'alter'
][
'text'
]);
unset
(
$form
[
'alter'
][
'help'
]);
return
$form
;
}
lib/Drupal/views/Plugin/views/query/Sql.php
View file @
e3d6b873
...
...
@@ -1209,8 +1209,8 @@ function compile_fields($fields_array, $query) {
if
(
!
empty
(
$field
[
'function'
]))
{
$info
=
$this
->
get_aggregation_info
();
if
(
!
empty
(
$info
[
$field
[
'function'
]][
'method'
])
&&
function_exists
(
$info
[
$field
[
'function'
]][
'method'
]))
{
$string
=
$info
[
$field
[
'function'
]][
'method'
](
$field
[
'function'
],
$string
);
if
(
!
empty
(
$info
[
$field
[
'function'
]][
'method'
])
&&
is_callable
(
array
(
$this
,
$info
[
$field
[
'function'
]][
'method'
]))
)
{
$string
=
$this
::
$info
[
$field
[
'function'
]][
'method'
](
$field
[
'function'
],
$string
);
$placeholders
=
!
empty
(
$field
[
'placeholders'
])
?
$field
[
'placeholders'
]
:
array
();
$query
->
addExpression
(
$string
,
$fieldname
,
$placeholders
);
}
...
...
@@ -1537,7 +1537,7 @@ function get_aggregation_info() {
),
'count'
=>
array
(
'title'
=>
t
(
'Count'
),
'method'
=>
'
views_query_default_
aggregation_method_simple'
,
'method'
=>
'aggregation_method_simple'
,
'handler'
=>
array
(
'argument'
=>
'groupby_numeric'
,
'field'
=>
'groupby_numeric'
,
...
...
@@ -1547,7 +1547,7 @@ function get_aggregation_info() {
),
'count_distinct'
=>
array
(
'title'
=>
t
(
'Count DISTINCT'
),
'method'
=>
'
views_query_default_
aggregation_method_distinct'
,
'method'
=>
'aggregation_method_distinct'
,
'handler'
=>
array
(
'argument'
=>
'groupby_numeric'
,
'field'
=>
'groupby_numeric'
,
...
...
@@ -1557,7 +1557,7 @@ function get_aggregation_info() {
),
'sum'
=>
array
(
'title'
=>
t
(
'Sum'
),
'method'
=>
'
views_query_default_
aggregation_method_simple'
,
'method'
=>
'aggregation_method_simple'
,
'handler'
=>
array
(
'argument'
=>
'groupby_numeric'
,
'field'
=>
'groupby_numeric'
,
...
...
@@ -1567,7 +1567,7 @@ function get_aggregation_info() {
),
'avg'
=>
array
(
'title'
=>
t
(
'Average'
),
'method'
=>
'
views_query_default_
aggregation_method_simple'
,
'method'
=>
'aggregation_method_simple'
,
'handler'
=>
array
(
'argument'
=>
'groupby_numeric'
,
'field'
=>
'groupby_numeric'
,
...
...
@@ -1577,7 +1577,7 @@ function get_aggregation_info() {
),
'min'
=>
array
(
'title'
=>
t
(
'Minimum'
),
'method'
=>
'
views_query_default_
aggregation_method_simple'
,
'method'
=>
'aggregation_method_simple'
,
'handler'
=>
array
(
'argument'
=>
'groupby_numeric'
,
'field'
=>
'groupby_numeric'
,
...
...
@@ -1587,7 +1587,7 @@ function get_aggregation_info() {
),
'max'
=>
array
(
'title'
=>
t
(
'Maximum'
),
'method'
=>
'
views_query_default_
aggregation_method_simple'
,
'method'
=>
'aggregation_method_simple'
,
'handler'
=>
array
(
'argument'
=>
'groupby_numeric'
,
'field'
=>
'groupby_numeric'
,
...
...
@@ -1597,7 +1597,7 @@ function get_aggregation_info() {
),
'stddev_pop'
=>
array
(
'title'
=>
t
(
'Standard derivation'
),
'method'
=>
'
views_query_default_
aggregation_method_simple'
,
'method'
=>
'aggregation_method_simple'
,
'handler'
=>
array
(
'argument'
=>
'groupby_numeric'
,
'field'
=>
'groupby_numeric'
,
...
...
@@ -1651,27 +1651,14 @@ function get_result_entities($results, $relationship = NULL) {
}
return
array
(
$entity_type
,
$result
);
}
}
function
views_query_default_aggregation_method_simple
(
$group_type
,
$field
)
{
return
strtoupper
(
$group_type
)
.
'('
.
$field
.
')'
;
}
function
views_query_default_aggregation_method_distinct
(
$group_type
,
$field
)
{
$group_type
=
str_replace
(
'_distinct'
,
''
,
$group_type
);
return
strtoupper
(
$group_type
)
.
'(DISTINCT '
.
$field
.
')'
;
}
function
aggregation_method_simple
(
$group_type
,
$field
)
{
return
strtoupper
(
$group_type
)
.
'('
.
$field
.
')'
;
}
/**
* Validation callback for query tags.
*/
function
views_element_validate_tags
(
$element
,
&
$form_state
)
{
$values
=
array_map
(
'trim'
,
explode
(
','
,
$element
[
'#value'
]));
foreach
(
$values
as
$value
)
{
if
(
preg_match
(
"/[^a-z_]/"
,
$value
))
{
form_error
(
$element
,
t
(
'The query tags may only contain lower-case alphabetical characters and underscores.'
));
return
;
}
function
aggregation_method_distinct
(
$group_type
,
$field
)
{
$group_type
=
str_replace
(
'_distinct'
,
''
,
$group_type
);
return
strtoupper
(
$group_type
)
.
'(DISTINCT '
.
$field
.
')'
;
}
}
}
lib/Views/field/Plugin/views/field/Field.php
View file @
e3d6b873
...
...
@@ -10,33 +10,6 @@
use
Drupal\views\Plugin\views\field\FieldPluginBase
;
use
Drupal\Core\Annotation\Plugin
;
/**
* Helper function: Return an array of formatter options for a field type.
*
* Borrowed from field_ui.
*/
function
_field_view_formatter_options
(
$field_type
=
NULL
)
{
$options
=
&
drupal_static
(
__FUNCTION__
);
if
(
!
isset
(
$options
))
{
$field_types
=
field_info_field_types
();
$options
=
array
();
foreach
(
field_info_formatter_types
()
as
$name
=>
$formatter
)
{
foreach
(
$formatter
[
'field types'
]
as
$formatter_field_type
)
{
// Check that the field type exists.
if
(
isset
(
$field_types
[
$formatter_field_type
]))
{
$options
[
$formatter_field_type
][
$name
]
=
$formatter
[
'label'
];
}
}
}
}
if
(
$field_type
)
{
return
!
empty
(
$options
[
$field_type
])
?
$options
[
$field_type
]
:
array
();
}
return
$options
;
}
/**
* A field that displays fieldapi fields.
*
...
...
views.module
View file @
e3d6b873
...
...
@@ -2435,6 +2435,58 @@ function views_process_check_options($element, &$form_state) {
return
$element
;
}
/**
* Validation callback for query tags.
*/
function
views_element_validate_tags
(
$element
,
&
$form_state
)
{
$values
=
array_map
(
'trim'
,
explode
(
','
,
$element
[
'#value'
]));
foreach
(
$values
as
$value
)
{
if
(
preg_match
(
"/[^a-z_]/"
,
$value
))
{
form_error
(
$element
,
t
(
'The query tags may only contain lower-case alphabetical characters and underscores.'
));
return
;
}
}
}
/**
* Prerender function to move the textarea to the top.
*/
function
views_handler_field_custom_pre_render_move_text
(
$form
)
{
$form
[
'text'
]
=
$form
[
'alter'
][
'text'
];
$form
[
'help'
]
=
$form
[
'alter'
][
'help'
];
unset
(
$form
[
'alter'
][
'text'
]);
unset
(
$form
[
'alter'
][
'help'
]);
return
$form
;
}
/**
* Helper function: Return an array of formatter options for a field type.
*
* Borrowed from field_ui.
*/
function
_field_view_formatter_options
(
$field_type
=
NULL
)
{
$options
=
&
drupal_static
(
__FUNCTION__
);
if
(
!
isset
(
$options
))
{
$field_types
=
field_info_field_types
();
$options
=
array
();
foreach
(
field_info_formatter_types
()
as
$name
=>
$formatter
)
{
foreach
(
$formatter
[
'field types'
]
as
$formatter_field_type
)
{
// Check that the field type exists.
if
(
isset
(
$field_types
[
$formatter_field_type
]))
{
$options
[
$formatter_field_type
][
$name
]
=
$formatter
[
'label'
];
}
}
}
}
if
(
$field_type
)
{
return
!
empty
(
$options
[
$field_type
])
?
$options
[
$field_type
]
:
array
();
}
return
$options
;
}
/**
* Trim the field down to the specified length.
*
...
...
Write
Preview
Supports
Markdown
0%
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!
Cancel
Please
register
or
sign in
to comment