You are here

public static function Anonymizer::propertyCanBeRemoved in General Data Protection Regulation 7

Check whether a property can be removed.

Parameters

string $entity_type: The entity type.

string $field: The field name.

array $property_info: The property info.

mixed $error_message: A variable to fill with an error message.

Return value

bool TRUE if the property can be removed, FALSE if not.

2 calls to Anonymizer::propertyCanBeRemoved()
Anonymizer::remove in modules/gdpr_tasks/src/Anonymizer.php
Removes the field value.
gdpr_fields_field_data_export_ui_form in modules/gdpr_fields/plugins/export_ui/gdpr_fields_ui.inc
Define the preset add/edit form.

File

modules/gdpr_tasks/src/Anonymizer.php, line 296

Class

Anonymizer
Anonymizes or removes field values for GDPR.

Code

public static function propertyCanBeRemoved($entity_type, $field, array $property_info, &$error_message = NULL) {

  // Fail on computed fields.
  if (!empty($property_info['computed'])) {
    $error_message = "Unable to remove computed property.";
    return FALSE;
  }

  // Check that this isn't a required entity property.
  $entity_info = entity_get_info($entity_type);
  if (!empty($entity_info['base table']) && empty($property_info['field'])) {
    $schema_field = isset($property_info['schema field']) ? $property_info['schema field'] : $field;
    $schema = drupal_get_schema($entity_info['base table']);

    // If the field is set to not NULL, fail.
    if (!empty($schema['fields'][$schema_field]['not null'])) {
      $error_message = t("Unable to remove required database field %field.", array(
        '%field' => $field,
      ));
      return FALSE;
    }
    if (in_array($schema_field, $schema['primary key'])) {
      $error_message = t("Unable to remove part of a primary key %field.", array(
        '%field' => $field,
      ));
      return FALSE;
    }
  }

  // Otherwise assume we can.
  return TRUE;
}