|
7 | 7 |
|
8 | 8 | use Drupal\commerce_order\Entity\OrderTypeInterface; |
9 | 9 | use Drupal\commerce_order\Plugin\Field\FieldFormatter\PriceCalculatedFormatter; |
| 10 | +use Drupal\Core\Access\AccessResult; |
| 11 | +use Drupal\Core\Entity\EntityInterface; |
10 | 12 | use Drupal\Core\Form\FormStateInterface; |
11 | 13 | use Drupal\Core\Render\Element; |
12 | 14 | use Drupal\entity\BundleFieldDefinition; |
| 15 | +use Drupal\field\FieldStorageConfigInterface; |
13 | 16 |
|
14 | 17 | /** |
15 | 18 | * Implements hook_theme(). |
@@ -194,3 +197,42 @@ function commerce_order_mail($key, &$message, $params) { |
194 | 197 | $message['subject'] = $params['subject']; |
195 | 198 | $message['body'][] = $params['body']; |
196 | 199 | } |
| 200 | + |
| 201 | +/** |
| 202 | + * Implements hook_ENTITY_TYPE_access(). |
| 203 | + * |
| 204 | + * Forbids the profile 'address' field from being deletable. |
| 205 | + * This is an alternative to locking the field which still leaves |
| 206 | + * the field editable. |
| 207 | + */ |
| 208 | +function commerce_product_field_storage_config_access(FieldStorageConfigInterface $field_storage, $operation) { |
| 209 | + if ($field_storage->id() == 'profile.address' && $operation == 'delete') { |
| 210 | + return AccessResult::forbidden(); |
| 211 | + } |
| 212 | + return AccessResult::neutral(); |
| 213 | +} |
| 214 | + |
| 215 | +/** |
| 216 | + * Implements hook_entity_operation_alter(). |
| 217 | + * |
| 218 | + * Hides the "Storage settings" operation for the profile 'address' field. |
| 219 | + */ |
| 220 | +function commerce_product_entity_operation_alter(array &$operations, EntityInterface $entity) { |
| 221 | + if ($entity->getEntityTypeId() == 'field_config' && $entity->id() == 'profile.customer.address') { |
| 222 | + unset($operations['storage-settings']); |
| 223 | + } |
| 224 | +} |
| 225 | + |
| 226 | +/** |
| 227 | + * Implements hook_form_FORM_ID_alter() for 'field_config_edit_form'. |
| 228 | + * |
| 229 | + * Hides the 'Available countries' setting for the profile 'address' field. |
| 230 | + * The setting is unused because in Commerce it is taken from the store. |
| 231 | + */ |
| 232 | +function commerce_product_form_field_config_edit_form_alter(array &$form, FormStateInterface $form_state) { |
| 233 | + /** @var \Drupal\Core\Field\FieldConfigInterface $entity */ |
| 234 | + $entity = $form_state->getFormObject()->getEntity(); |
| 235 | + if ($entity->id() == 'profile.customer.address') { |
| 236 | + $form['settings']['available_countries']['#access'] = FALSE; |
| 237 | + } |
| 238 | +} |
0 commit comments