Skip to content
This repository has been archived by the owner on Jun 7, 2022. It is now read-only.

Commit

Permalink
Merge pull request #1 from wearewondrous/d9-compatibility
Browse files Browse the repository at this point in the history
Add D9 compatibility to module
  • Loading branch information
bia-wtag authored Jul 13, 2021
2 parents 386c611 + 31c7957 commit 44bf3ec
Show file tree
Hide file tree
Showing 11 changed files with 37 additions and 37 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
vendor/
.idea/
1 change: 0 additions & 1 deletion src/Annotation/BlockSettings.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,4 @@ class BlockSettings extends Plugin {
* @var bool
*/
public $area;

}
15 changes: 7 additions & 8 deletions src/Plugin/BlockSettings/ContextualFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
use Drupal\Core\Form\FormStateInterface;
use Drupal\views\Plugin\Block\ViewsBlock;
use Drupal\Core\Plugin\Context\Context;
use Drupal\Core\Plugin\Context\ContextDefinition;
use Drupal\Core\Plugin\Context\EntityContextDefinition;
use Drupal\taxonomy\Entity\Term;

/**
Expand Down Expand Up @@ -135,7 +135,7 @@ function getExposedPossibleValues($id, $handler) {
}
$terms = Term::loadMultiple($query->execute());
foreach ($terms as $term) {
$values[$term->id()] = \Drupal::entityManager()
$values[$term->id()] = \Drupal::service("entity.repository")
->getTranslationFromContext($term)
->label();
}
Expand All @@ -159,15 +159,15 @@ function getContextualPossibleValues($id, $handler) {
$options['exception']['value'] => $options['exception']['title'],
];
foreach ($validate_bundles as $bundle) {
$terms = \Drupal::entityManager()
->getStorage('taxonomy_term')
->loadTree($bundle);
$terms = \Drupal::entityTypeManager()
->getStorage('taxonomy_term')
->loadMultiple($bundle);
foreach ($terms as $term) {
$values[$term->tid] = $term->name;
}
}
break;
// TODO more generic way to work with other entity types as well.
// TODO more generic way to work with other entity types as well.
case "entity:node":
list($entity, $entity_type) = explode(':', $validation_type);
$options = $handler->options;
Expand Down Expand Up @@ -259,7 +259,7 @@ public function setContextualFilters($block) {
if ($values['enabled']) {
$contextual_filter_value = $values['value'];
$contextual_filter_type = $this->getContextualFilterValidationType($id);
$context_definition = new ContextDefinition($contextual_filter_type, $id);
$context_definition = new EntityContextDefinition($contextual_filter_type, $id);
$context_definition->setDefaultValue($contextual_filter_value);
$block->setContext($id, new Context($context_definition, $contextual_filter_value));
}
Expand Down Expand Up @@ -291,5 +291,4 @@ public function getContextualFilterValidationType($id) {
public function getMultiValueSeparator() {
return '+';
}

}
11 changes: 6 additions & 5 deletions src/Plugin/BlockSettings/EntityReferenceTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,12 @@ public function buildEntityReferenceSettingsForm(&$form, FormStateInterface $for
// "Warning: Invalid argument supplied for foreach()
// in Drupal\Core\Render\Element\Checkboxes::valueCallback()"
// @see \Drupal\user\Plugin\EntityReferenceSelection\UserSelection::buildConfigurationForm
if ($target_type == 'user'
if (
$target_type == 'user'
&& isset($selection_settings['filter']['type'])
&& $selection_settings['filter']['type'] == 'role'
&& empty($selection_settings['filter']['role'])) {
&& empty($selection_settings['filter']['role'])
) {
$selection_settings['filter']['role'] = [];
}

Expand All @@ -73,7 +75,7 @@ public function buildEntityReferenceSettingsForm(&$form, FormStateInterface $for

$subform['entity_reference'] = [
'#type' => 'fieldset',
'#title' => t('Entity reference settings'),
'#title' => 'Entity reference settings',
'#weight' => -40,
'#tree' => TRUE,
'#prefix' => '<div id="entity-reference-selection-wrapper">',
Expand All @@ -85,7 +87,7 @@ public function buildEntityReferenceSettingsForm(&$form, FormStateInterface $for
'#title' => $this->t('Type of item to reference'),
'#options' => $target_type_options,
'#required' => TRUE,
'#empty_option' => t('- Select a target type -'),
'#empty_option' => $this->t('- Select a target type -'),
'#default_value' => $target_type,
'#ajax' => [
'callback' => [get_called_class(), 'entityReferenceAjaxCallback'],
Expand Down Expand Up @@ -181,5 +183,4 @@ public static function entityReferenceAjaxCallback(array $form, FormStateInterfa
$element = NestedArray::getValue($form, array_slice($button['#array_parents'], 0, -1));
return $element;
}

}
15 changes: 8 additions & 7 deletions src/Plugin/BlockSettings/EntityTypeBundleSelectionTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public function buildSelectionSettingsForm(&$form, FormStateInterface $form_stat

$subform['entity_reference'] = [
'#type' => 'fieldset',
'#title' => t('Entity reference settings'),
'#title' => 'Entity reference settings',
'#weight' => -40,
'#prefix' => '<div id="entity-reference-selection-wrapper">',
'#suffix' => '</div>',
Expand All @@ -46,7 +46,7 @@ public function buildSelectionSettingsForm(&$form, FormStateInterface $form_stat
'#title' => $this->t('Type of item to reference'),
'#options' => $target_type_options,
'#required' => TRUE,
'#empty_option' => t('- Select a target type -'),
'#empty_option' => $this->t('- Select a target type -'),
'#default_value' => $target_type,
'#ajax' => [
'callback' => [get_called_class(), 'entityTypeAjaxCallback'],
Expand All @@ -60,7 +60,7 @@ public function buildSelectionSettingsForm(&$form, FormStateInterface $form_stat
'#title' => $this->t('Bundle'),
'#options' => $bundle_options,
'#required' => TRUE,
'#empty_option' => t('- Select a bundle type -'),
'#empty_option' => $this->t('- Select a bundle type -'),
'#default_value' => $bundle_type,
];

Expand Down Expand Up @@ -96,13 +96,15 @@ public function getEntityTypes() {
* List of bundles.
*/
public function getBundles($target_type) {
$options = \Drupal::entityManager()
$options = \Drupal::service("entity_type.bundle.info")
->getBundleInfo($target_type);

array_walk($options,
array_walk(
$options,
function ($item, $key) use (&$options) {
$options[$key] = $item['label'];
});
}
);

return $options;
}
Expand All @@ -123,5 +125,4 @@ public static function entityTypeAjaxCallback(array $form, FormStateInterface $f
$element = NestedArray::getValue($form, array_slice($button['#array_parents'], 0, -1));
return $element;
}

}
7 changes: 3 additions & 4 deletions src/Plugin/BlockSettings/InlineEntity.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ public function blockSubmit(ViewsBlock $block, $form, FormStateInterface $form_s
* Provide the default form for setting options.
*/
public function buildOptionsForm(&$form, FormStateInterface $form_state) {
$subform = $this->buildSelectionSettingsForm($form, $form_state);
return $subform;
$subform = $this->buildSelectionSettingsForm($form, $form_state);
return $subform;
}

/**
Expand Down Expand Up @@ -148,7 +148,7 @@ public function buildAreaOptionsForm(array &$form, FormStateInterface $form_stat
$display_options = $this->getDisplayOptions();
$entity_type = $display_options['entity_reference']['target_type'];

$options = \Drupal::entityManager()->getViewModeOptions($entity_type);
$options = \Drupal::service("entity_display.repository")->getViewModeOptions($entity_type);

// Build the setting form.
$form['view_mode'] = [
Expand Down Expand Up @@ -185,5 +185,4 @@ public function renderArea(array $context) {

return $render;
}

}
3 changes: 1 addition & 2 deletions src/Plugin/BlockSettings/NodeReference.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ public function blockForm(ViewsBlock $block, array $form, FormStateInterface $fo
'#default_value' => $default_value,
);

return $subform;
return $subform;
}

}
5 changes: 2 additions & 3 deletions src/Plugin/Derivative/ViewsEntityRowDynamicFormat.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ class ViewsEntityRowDynamicFormat extends ViewsEntityRow {
*/
public function getDerivativeDefinitions($base_plugin_definition) {
parent::getDerivativeDefinitions($base_plugin_definition);
foreach ($this->entityManager->getDefinitions() as $entity_type_id => $entity_type) {
foreach ($this->entityTypeManager->getDefinitions() as $entity_type_id => $entity_type) {
// Just add support for entity types which have a views integration.
if (($base_table = $entity_type->getBaseTable()) && $this->viewsData->get($base_table) && $this->entityManager->hasHandler($entity_type_id, 'view_builder')) {
if (($base_table = $entity_type->getBaseTable()) && $this->viewsData->get($base_table) && $this->entityTypeManager->hasHandler($entity_type_id, 'view_builder')) {
$this->derivatives[$entity_type_id] = [
'title' => 'Content (with dynamic view mode)'
] + $this->derivatives[$entity_type_id];
Expand All @@ -33,5 +33,4 @@ public function getDerivativeDefinitions($base_plugin_definition) {

return $this->derivatives;
}

}
3 changes: 1 addition & 2 deletions src/Plugin/views/row/EntityRowWithDynamicFormat.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ public function getViewModeOverride(ViewExecutable $view, DisplayPluginBase $dis
* @return array
*/
public function getFormatOptions() {
return \Drupal::entityManager()->getViewModeOptions($this->entityTypeId);
return \Drupal::service("entity_display.repository")->getViewModeOptions($this->entityTypeId);
}

}
1 change: 1 addition & 0 deletions views_block_overrides.info.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ name: Views block overrides
type: module
description: Allows block displays to override block configuration.
core: 8.x
core_version_requirement: ^8 || ^9
package: Views
dependencies:
- views
Expand Down
11 changes: 6 additions & 5 deletions views_block_overrides.module
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use Drupal\views\Plugin\views\display\Block as CoreBlock;
use Drupal\ctools_views\Plugin\Display\Block as CtoolsBlock;
use Drupal\views_block_overrides\Plugin\views\display\CtoolsBlockOverrides;
use Drupal\views_block_overrides\Plugin\Block\ViewsBlockOverride;

/**
* Implements hook_field_widget_FIELD-ID_FORM_alter().
*
Expand All @@ -28,7 +29,7 @@ function views_block_overrides_field_widget_block_field_default_form_alter(&$ele
];
foreach ($hiden_elements as $name) {
if (isset($element['settings'][$name])) {
// $element['settings'][$name]['#access'] = FALSE;
// $element['settings'][$name]['#access'] = FALSE;
}
}
}
Expand All @@ -38,9 +39,9 @@ function views_block_overrides_field_widget_block_field_default_form_alter(&$ele
* Implements hook_views_plugins_display_alter().
*/
function views_block_overrides_views_plugins_display_alter(&$displays) {
// if (!empty($displays['block']['class']) && $displays['block']['class'] == CtoolsBlock::class) {
// $displays['block']['class'] = CtoolsBlockOverrides::class;
// }
// if (!empty($displays['block']['class']) && $displays['block']['class'] == CtoolsBlock::class) {
// $displays['block']['class'] = CtoolsBlockOverrides::class;
// }
}

/**
Expand Down Expand Up @@ -125,4 +126,4 @@ function views_block_overrides_theme_suggestions_views_block_overrides_area_alte
foreach ($new_suggestions as $suggestion) {
$suggestions[] = implode('__', $suggestion);
}
}
}

0 comments on commit 44bf3ec

Please sign in to comment.