Commit de2cb794 authored by dermario's avatar dermario Committed by drunken monkey

Issue #2596471 by dermario, drunken monkey: Added data type descriptions to the "Fields" tab.

parent f484345c
......@@ -80,7 +80,11 @@ function theme_search_api_admin_fields_table($variables) {
*
* @param array $variables
* An associative array containing:
* - data_types: An array of data types.
* - data_types: An associative array of data types, keyed by data type ID and
* containing associative arrays with information about the data type:
* - label: The (translated) human-readable label for the data type.
* - description: The (translated) description of the data type.
* - fallback: The type ID of the fallback type.
* - fallback_mapping: array of fallback data types for unsupported data
* types.
*
......@@ -92,7 +96,11 @@ function theme_search_api_admin_fields_table($variables) {
function theme_search_api_admin_data_type_table(array $variables) {
$data_types = $variables['data_types'];
$fallback_mapping = $variables['fallback_mapping'];
$header = array(t('Data Type'), t('Supported'));
$header = array(
t('Data Type'),
t('Description'),
t('Supported'),
);
// Only show the column with fallback types if there is actually an
// unsupported type listed.
if ($fallback_mapping) {
......@@ -118,6 +126,7 @@ function theme_search_api_admin_data_type_table(array $variables) {
$row = array(
$data_type['label'],
$data_type['description'],
array('data' => $supported_icon),
);
......
......@@ -32,6 +32,15 @@ class SearchApiDataType extends Plugin {
*/
public $label;
/**
* The description of the data type.
*
* @ingroup plugin_translatable
*
* @var \Drupal\Core\Annotation\Translation
*/
public $description;
/**
* Whether this is one of the default data types provided by the Search API.
*
......
......@@ -16,13 +16,18 @@ use Drupal\Component\Plugin\PluginInspectionInterface;
interface DataTypeInterface extends PluginInspectionInterface, DerivativeInspectionInterface {
/**
* Returns the label for use on the administration pages.
* Returns the label of the data type.
*
* @return string
* The administration label.
*/
public function label();
/**
* Returns the description of the data type.
*/
public function getDescription();
/**
* Converts a field value to match the data type (if needed).
*
......
......@@ -15,6 +15,8 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
* keys:
* - id: The unique, system-wide identifier of the data type class.
* - label: The human-readable name of the data type class, translated.
* - description: A human-readable description for the data type class,
* translated.
* - fallback_type: (optional) The fallback data type for this data type. Needs
* to be one of the default data types defined in the Search API itself.
* Defaults to "text".
......@@ -25,6 +27,7 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
* @SearchApiDataType(
* id = "my_data_type",
* label = @Translation("My data type"),
* description = @Translation("Some information about my data type"),
* fallback_type = "string"
* )
* @endcode
......@@ -113,4 +116,12 @@ abstract class DataTypePluginBase extends PluginBase implements DataTypeInterfac
return $plugin_definition['label'];
}
/**
* {@inheritdoc}
*/
public function getDescription() {
$plugin_definition = $this->getPluginDefinition();
return $plugin_definition['description'];
}
}
......@@ -233,6 +233,7 @@ class IndexFieldsForm extends EntityForm {
foreach($instances as $name => $type) {
$data_types[$name] = [
'label' => $type->label(),
'description' => $type->getDescription(),
'fallback' => $type->getFallbackType(),
];
}
......
......@@ -10,6 +10,7 @@ use Drupal\search_api\DataType\DataTypePluginBase;
* @SearchApiDataType(
* id = "boolean",
* label = @Translation("Boolean"),
* description = @Translation("Boolean fields can only have one of two values: true or false."),
* default = "true"
* )
*/
......
......@@ -10,6 +10,7 @@ use Drupal\search_api\DataType\DataTypePluginBase;
* @SearchApiDataType(
* id = "date",
* label = @Translation("Date"),
* description = @Translation("Represents points in time."),
* default = "true"
* )
*/
......
......@@ -10,6 +10,7 @@ use Drupal\search_api\DataType\DataTypePluginBase;
* @SearchApiDataType(
* id = "decimal",
* label = @Translation("Decimal"),
* description = @Translation("Contains numeric, typically non-integer values."),
* default = "true"
* )
*/
......
......@@ -10,6 +10,7 @@ use Drupal\search_api\DataType\DataTypePluginBase;
* @SearchApiDataType(
* id = "integer",
* label = @Translation("Integer"),
* description = @Translation("Contains integer values."),
* default = "true"
* )
*/
......
......@@ -10,6 +10,7 @@ use Drupal\search_api\DataType\DataTypePluginBase;
* @SearchApiDataType(
* id = "string",
* label = @Translation("String"),
* description = @Translation("String fields are used for short, keyword-like character strings where you only want to find complete field values, not individual words."),
* default = "true"
* )
*/
......
......@@ -10,6 +10,7 @@ use Drupal\search_api\DataType\DataTypePluginBase;
* @SearchApiDataType(
* id = "text",
* label = @Translation("Fulltext"),
* description = @Translation("Fulltext fields are analyzed fields which are made available for fulltext search. This data type should be used for any fields (usually with free text input by users) which you want to search for individual words."),
* default = "true"
* )
*/
......
......@@ -670,8 +670,8 @@ class IntegrationTest extends WebTestBase {
/** @var \SimpleXMLElement $row */
foreach ($rows as $row) {
$label = (string) $row->td[0];
$icon = basename($row->td[1]->img['src']);
$fallback = (string) $row->td[2];
$icon = basename($row->td[2]->img['src']);
$fallback = (string) $row->td[3];
// Make sure we display the right icon and fallback column.
if (strpos($label, 'Unsupported') === 0) {
......
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