Skip to content
Snippets Groups Projects
Commit 12df3445 authored by Lee Rowlands's avatar Lee Rowlands
Browse files

Coding standards

parent fdb1fb92
No related branches found
No related tags found
No related merge requests found
......@@ -9,19 +9,19 @@
* Implements hook_drush_command().
*/
function entity_hierarchy_drush_command() {
$items = array();
$items = [];
$items['entity-hierarchy-rebuild-tree'] = array(
$items['entity-hierarchy-rebuild-tree'] = [
'description' => 'Rebuild tree.',
'arguments' => array(
'arguments' => [
'field_name' => dt('Field machine name'),
'entity_type_id' => dt('Entity type id'),
),
'options' => array(),
'examples' => array(
],
'options' => [],
'examples' => [
'drush entity-hierarchy-rebuild-tree field_parents node' => 'Rebuild tree for node field named field_parents.',
),
);
],
];
return $items;
}
......
......@@ -102,7 +102,7 @@ class HierarchyBasedBreadcrumbBuilder implements BreadcrumbBuilderInterface {
*/
public function build(RouteMatchInterface $route_match) {
$breadcrumb = new Breadcrumb();
/** @var ContentEntityInterface $route_entity */
/** @var \Drupal\Core\Entity\ContentEntityInterface $route_entity */
$route_entity = $this->getEntityFromRouteMatch($route_match);
$breadcrumb->addCacheableDependency($route_match->getRouteObject());
......
......@@ -12,7 +12,6 @@ use Symfony\Component\Validator\ExecutionContextInterface;
* @Constraint(
* id = "ValidHierarchySection",
* label = @Translation("Valid hierarchy selection", context = "Validation"),
* type = "entity:comment"
* )
*/
class ValidEntityHierarchySection extends Constraint implements ConstraintValidatorInterface {
......
......@@ -110,10 +110,10 @@ class EntityHierarchy extends DefaultSelection {
$result = $query->execute();
if (empty($result)) {
return array();
return [];
}
$options = array();
$options = [];
$entities = $this->entityManager->getStorage($target_type)->loadMultiple($result);
// We assume target and definition are one and the same, as there is no
......
......@@ -25,7 +25,7 @@ class EntityReferenceHierarchyLabelFormatter extends EntityReferenceLabelFormatt
*/
public function settingsForm(array $form, FormStateInterface $form_state) {
$elements = parent::settingsForm($form, $form_state);
$elements['weight_output'] = array(
$elements['weight_output'] = [
'#type' => 'radios',
'#options' => [
'suffix' => t('After title'),
......@@ -34,7 +34,7 @@ class EntityReferenceHierarchyLabelFormatter extends EntityReferenceLabelFormatt
'#title' => t('Output weigh'),
'#default_value' => $this->getSetting('weight_output'),
'#required' => TRUE,
);
];
return $elements;
}
......@@ -54,7 +54,7 @@ class EntityReferenceHierarchyLabelFormatter extends EntityReferenceLabelFormatt
$action = t('suffix after title');
break;
}
$summary[] = t('Show weight as @action', array('@action' => $action));
$summary[] = t('Show weight as @action', ['@action' => $action]);
return $summary;
}
......
......@@ -54,10 +54,10 @@ class EntityReferenceHierarchy extends EntityReferenceItem {
*/
public static function schema(FieldStorageDefinitionInterface $field_definition) {
$schema = parent::schema($field_definition);
$schema['columns']['weight'] = array(
$schema['columns']['weight'] = [
'type' => 'int',
'unsigned' => FALSE,
);
];
return $schema;
}
......@@ -65,11 +65,11 @@ class EntityReferenceHierarchy extends EntityReferenceItem {
* {@inheritdoc}
*/
public static function defaultFieldSettings() {
return array(
return [
'weight_label' => t('Weight'),
'weight_min' => self::HIERARCHY_MIN_CHILD_WEIGHT,
'weight_max' => self::HIERARCHY_MAX_CHILD_WEIGHT,
) + parent::defaultFieldSettings();
] + parent::defaultFieldSettings();
}
/**
......@@ -106,7 +106,7 @@ class EntityReferenceHierarchy extends EntityReferenceItem {
// list of field-types with options for each destination entity type.
// Too much work, we'll just make people fill that out later.
// Also, keeps the field type dropdown from getting too cluttered.
return array();
return [];
}
/**
......
......@@ -26,24 +26,24 @@ class EntityReferenceHierarchySelect extends OptionsWidgetBase {
*/
public function formElement(FieldItemListInterface $items, $delta, array $element, array &$form, FormStateInterface $form_state) {
$element = parent::formElement($items, $delta, $element, $form, $form_state);
$element += array(
$element += [
'#type' => 'select',
'#options' => $this->getOptions($items->getEntity()),
'#default_value' => isset($items[$delta]->target_id) ? $items[$delta]->target_id : '',
);
];
$widget = array(
$widget = [
'#attributes' => ['class' => ['form--inline', 'clearfix']],
'#theme_wrappers' => ['container'],
);
];
$widget['target_id'] = $element;
$widget['weight'] = array(
$widget['weight'] = [
'#type' => 'number',
'#size' => '4',
'#default_value' => isset($items[$delta]) ? $items[$delta]->weight : 1,
'#weight' => 10,
);
];
kint($widget);
if ($this->fieldDefinition->getFieldStorageDefinition()->isMultiple()) {
......@@ -92,7 +92,7 @@ class EntityReferenceHierarchySelect extends OptionsWidgetBase {
public static function validateElement(array $element, FormStateInterface $form_state) {
if ($element['#value'] == '_none') {
if ($element['#required'] && $element['#value'] == '_none') {
$form_state->setError($element, t('@name field is required.', array('@name' => $element['#title'])));
$form_state->setError($element, t('@name field is required.', ['@name' => $element['#title']]));
}
else {
$form_state->setValueForElement($element, NULL);
......
......@@ -64,6 +64,8 @@ class HierarchyIsChildOfEntity extends ArgumentPluginBase {
* Entity type manager.
* @param \Drupal\entity_hierarchy\Storage\NestedSetNodeKeyFactory $nodeKeyFactory
* Node key factory.
* @param \Drupal\Core\Database\Connection $database
* Database connection.
*/
public function __construct(array $configuration, $plugin_id, $plugin_definition, NestedSetStorageFactory $nestedSetStorageFactory, EntityTypeManagerInterface $entityTypeManager, NestedSetNodeKeyFactory $nodeKeyFactory, Connection $database) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
......@@ -167,7 +169,7 @@ class HierarchyIsChildOfEntity extends ArgumentPluginBase {
$options = parent::defineOptions();
// Allow filtering depth as well.
$options['depth'] = array('default' => 0);
$options['depth'] = ['default' => 0];
return $options;
}
......
......@@ -39,10 +39,10 @@ class HideWeightFieldFunctionalTest extends BrowserTestBase {
$this->setupEntityHierarchyField(static::ENTITY_TYPE, static::ENTITY_TYPE, static::FIELD_NAME);
$this->additionalSetup();
$this->getEntityFormDisplay(self::ENTITY_TYPE, self::ENTITY_TYPE, 'default')
->setComponent(self::FIELD_NAME, array(
->setComponent(self::FIELD_NAME, [
'type' => 'entity_reference_hierarchy_autocomplete',
'weight' => 20,
))
])
->save();
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment