Fix: Buttons not translateable #477

This commit is contained in:
Michael Stenta 2022-01-11 08:59:03 -05:00
commit 232557027d
3 changed files with 12 additions and 6 deletions

View File

@ -20,6 +20,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Fixed
- Make local action buttons translatable.
- Fix permission for map settings form (/farm/settings/map).
- Patch `jsonapi_schema` module to fix
[Issue #3256795: Float fields have a null schema](https://www.drupal.org/project/jsonapi_schema/issues/3256795)

View File

@ -3,20 +3,25 @@
namespace Drupal\farm_ui_action\Plugin\Derivative;
use Drupal\Component\Plugin\Derivative\DeriverBase;
use Drupal\Component\Utility\Unicode;
use Drupal\Core\StringTranslation\StringTranslationTrait;
/**
* Defines farmOS action links.
*/
class FarmActions extends DeriverBase {
use StringTranslationTrait;
/**
* {@inheritdoc}
*/
public function getDerivativeDefinitions($base_plugin_definition) {
// Load the entity type manager.
$entity_type_manager = \Drupal::entityTypeManager();
// Load available entity types.
$entity_types = array_keys(\Drupal::entityTypeManager()->getDefinitions());
$entity_types = array_keys($entity_type_manager->getDefinitions());
// Define the farmOS entity types we care about.
$farm_types = [
@ -35,8 +40,9 @@ class FarmActions extends DeriverBase {
// Generate a link to [entity-type]/add.
$name = 'farm.add.' . $type;
$entity_type_label = $entity_type_manager->getStorage($type)->getEntityType()->getLabel();
$this->derivatives[$name] = $base_plugin_definition;
$this->derivatives[$name]['title'] = 'Add ' . Unicode::ucfirst($type);
$this->derivatives[$name]['title'] = $this->t('Add :entity_type', [':entity_type' => $entity_type_label]);
$this->derivatives[$name]['route_name'] = 'entity.' . $type . '.add_page';
// Add it to entity Views, if the farm_ui_views module is enabled.

View File

@ -3,7 +3,6 @@
namespace Drupal\farm_ui_action\Plugin\Menu\LocalAction;
use Drupal\asset\Entity\AssetInterface;
use Drupal\Component\Utility\Unicode;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Menu\LocalActionDefault;
use Drupal\Core\Routing\RouteMatch;
@ -70,8 +69,8 @@ class AddEntity extends LocalActionDefault {
// Get the entity type.
$entity_type = $this->entityTypeManager->getDefinition($this->pluginDefinition['entity_type']);
// Get the entity type label (lowercase).
$entity_type_label = Unicode::lcfirst($entity_type->getLabel());
// Get the entity type label.
$entity_type_label = $entity_type->getLabel();
// Get the bundle machine name.
$route_match = RouteMatch::createFromRequest($request);