You are here

class SocialProfileFieldsFlushForm in Open Social 10.3.x

Same name and namespace in other branches
  1. 8.9 modules/social_features/social_profile/modules/social_profile_fields/src/Form/SocialProfileFieldsFlushForm.php \Drupal\social_profile_fields\Form\SocialProfileFieldsFlushForm
  2. 8.2 modules/social_features/social_profile/modules/social_profile_fields/src/Form/SocialProfileFieldsFlushForm.php \Drupal\social_profile_fields\Form\SocialProfileFieldsFlushForm
  3. 8.3 modules/social_features/social_profile/modules/social_profile_fields/src/Form/SocialProfileFieldsFlushForm.php \Drupal\social_profile_fields\Form\SocialProfileFieldsFlushForm
  4. 8.4 modules/social_features/social_profile/modules/social_profile_fields/src/Form/SocialProfileFieldsFlushForm.php \Drupal\social_profile_fields\Form\SocialProfileFieldsFlushForm
  5. 8.5 modules/social_features/social_profile/modules/social_profile_fields/src/Form/SocialProfileFieldsFlushForm.php \Drupal\social_profile_fields\Form\SocialProfileFieldsFlushForm
  6. 8.6 modules/social_features/social_profile/modules/social_profile_fields/src/Form/SocialProfileFieldsFlushForm.php \Drupal\social_profile_fields\Form\SocialProfileFieldsFlushForm
  7. 8.7 modules/social_features/social_profile/modules/social_profile_fields/src/Form/SocialProfileFieldsFlushForm.php \Drupal\social_profile_fields\Form\SocialProfileFieldsFlushForm
  8. 8.8 modules/social_features/social_profile/modules/social_profile_fields/src/Form/SocialProfileFieldsFlushForm.php \Drupal\social_profile_fields\Form\SocialProfileFieldsFlushForm
  9. 10.0.x modules/social_features/social_profile/modules/social_profile_fields/src/Form/SocialProfileFieldsFlushForm.php \Drupal\social_profile_fields\Form\SocialProfileFieldsFlushForm
  10. 10.1.x modules/social_features/social_profile/modules/social_profile_fields/src/Form/SocialProfileFieldsFlushForm.php \Drupal\social_profile_fields\Form\SocialProfileFieldsFlushForm
  11. 10.2.x modules/social_features/social_profile/modules/social_profile_fields/src/Form/SocialProfileFieldsFlushForm.php \Drupal\social_profile_fields\Form\SocialProfileFieldsFlushForm

Class SocialProfileFieldsFlushForm.

Provides confirmation form for resetting a vocabulary to alphabetical order.

Hierarchy

Expanded class hierarchy of SocialProfileFieldsFlushForm

1 string reference to 'SocialProfileFieldsFlushForm'
social_profile_fields.routing.yml in modules/social_features/social_profile/modules/social_profile_fields/social_profile_fields.routing.yml
modules/social_features/social_profile/modules/social_profile_fields/social_profile_fields.routing.yml

File

modules/social_features/social_profile/modules/social_profile_fields/src/Form/SocialProfileFieldsFlushForm.php, line 18

Namespace

Drupal\social_profile_fields\Form
View source
class SocialProfileFieldsFlushForm extends ConfirmFormBase {

  /**
   * Profilestorage.
   *
   * @var \Drupal\profile\ProfileStorage
   */
  protected $profileStorage;

  /**
   * Configstorage.
   *
   * @var \Drupal\Core\Config\ConfigFactory
   */
  protected $configFactory;

  /**
   * Fiekdconfigstorage.
   *
   * @var \Drupal\field\FieldConfigStorage
   */
  protected $fieldStorage;

  /**
   * Constructs a new ExportUserConfirm.
   *
   * @param \Drupal\profile\ProfileStorage $profiel_storage
   *   The profile storage.
   * @param \Drupal\Core\Config\ConfigFactory $config_factory
   *   The config.
   * @param \Drupal\field\FieldConfigStorage $field_storage
   *   The field storage.
   */
  public function __construct(ProfileStorage $profiel_storage, ConfigFactory $config_factory, FieldConfigStorage $field_storage) {
    $this->profileStorage = $profiel_storage;
    $this->configFactory = $config_factory;
    $this->fieldStorage = $field_storage;
  }

  /**
   * {@inheritdoc}
   */
  public static function create(ContainerInterface $container) {
    return new static($container
      ->get('entity_type.manager')
      ->getStorage('profile'), $container
      ->get('config.factory'), $container
      ->get('entity_type.manager')
      ->getStorage('field_config'));
  }

  /**
   * {@inheritdoc}
   */
  public function getFormId() {
    return 'social_profile_fields_flush_form';
  }

  /**
   * {@inheritdoc}
   */
  public function getQuestion() {
    return $this
      ->t('Flush profile.');
  }

  /**
   * {@inheritdoc}
   */
  public function getCancelUrl() {
    return new Url('social_profile_fields.settings');
  }

  /**
   * {@inheritdoc}
   */
  public function getConfirmText() {
    return $this
      ->t('Yes, continue');
  }

  /**
   * {@inheritdoc}
   */
  public function submitForm(array &$form, FormStateInterface $form_state) {
    $pids = \Drupal::entityQuery('profile')
      ->condition('type', 'profile')
      ->execute();
    $fields = $this
      ->getUnselectedFields();
    $batch = [
      'title' => t('Flushing profiles.'),
      'operations' => [
        [
          '\\Drupal\\social_profile_fields\\SocialProfileFieldsBatch::performFlush',
          [
            $pids,
            $fields,
          ],
        ],
      ],
      'finished' => '\\Drupal\\social_profile_fields\\SocialProfileFieldsBatch::performFlushFinishedCallback',
    ];
    batch_set($batch);
    $form_state
      ->setRedirectUrl($this
      ->getCancelUrl());
  }

  /**
   * {@inheritdoc}
   */
  public function getDescription() {
    $fields = $this
      ->getUnselectedFields();
    $field_string = implode(', ', $fields);
    return $this
      ->t('<strong>WARNING</strong>: Flushing profile data will permanently <strong>remove all data</strong> from the following fields from the database: %fields. The search indexes may also be cleared and will need re-indexing. This <strong>cannot be undone</strong>. Are you sure you want to continue?', [
      '%fields' => $field_string,
    ]);
  }

  /**
   * Function that return an array of field names.
   *
   * @return array
   *   An array of field names.
   */
  protected function getUnselectedFields() {
    $profile_fields = $this->fieldStorage
      ->loadByProperties([
      'entity_type' => 'profile',
      'bundle' => 'profile',
    ]);
    $settings = $this->configFactory
      ->get('social_profile_fields.settings');
    $empty = [];

    /** @var \Drupal\field\Entity\FieldConfig $value */
    foreach ($profile_fields as $key => $value) {
      $setting_id = str_replace('.', '_', $key);
      $sval = $settings
        ->get($setting_id);
      if (isset($sval) && $sval == FALSE) {
        $empty[] = $value
          ->getName();
      }
      if ($setting_id === 'profile_profile_field_profile_address') {
        if (isset($sval) && $sval == FALSE) {
          $empty[] = 'country';
        }
        $city_val = $settings
          ->get('profile_address_field_city');
        if (isset($city_val) && $city_val == FALSE) {
          $empty[] = 'locality';
        }
        $address_val = $settings
          ->get('profile_address_field_address');
        if (isset($address_val) && $address_val == FALSE) {
          $empty[] = 'addressLine1';
        }
        $postalcode_val = $settings
          ->get('profile_address_field_postalcode');
        if (isset($postalcode_val) && $postalcode_val == FALSE) {
          $empty[] = 'postalCode';
        }
        $administrativearea_val = $settings
          ->get('profile_address_field_administrative_area');
        if (isset($administrativearea_val) && $administrativearea_val == FALSE) {
          $empty[] = 'administrativeArea';
        }
      }
    }
    return $empty;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ConfirmFormBase::buildForm public function Form constructor. Overrides FormInterface::buildForm 25
ConfirmFormBase::getCancelText public function Returns a caption for the link which cancels the action. Overrides ConfirmFormInterface::getCancelText 2
ConfirmFormBase::getFormName public function Returns the internal name used to refer to the confirmation item. Overrides ConfirmFormInterface::getFormName
DependencySerializationTrait::$_entityStorages protected property
DependencySerializationTrait::$_serviceIds protected property
DependencySerializationTrait::__sleep public function 2
DependencySerializationTrait::__wakeup public function 2
FormBase::$requestStack protected property The request stack. 1
FormBase::$routeMatch protected property The route match.
FormBase::config protected function Retrieves a configuration object.
FormBase::configFactory protected function Gets the config factory for this form. 3
FormBase::container private function Returns the service container.
FormBase::currentUser protected function Gets the current user.
FormBase::getRequest protected function Gets the request object.
FormBase::getRouteMatch protected function Gets the route match.
FormBase::logger protected function Gets the logger for a specific channel.
FormBase::redirect protected function Returns a redirect response object for the specified route.
FormBase::resetConfigFactory public function Resets the configuration factory.
FormBase::setConfigFactory public function Sets the config factory for this form.
FormBase::setRequestStack public function Sets the request stack object to use.
FormBase::validateForm public function Form validation handler. Overrides FormInterface::validateForm 72
LoggerChannelTrait::$loggerFactory protected property The logger channel factory service.
LoggerChannelTrait::getLogger protected function Gets the logger for a specific channel.
LoggerChannelTrait::setLoggerFactory public function Injects the logger channel factory.
MessengerTrait::$messenger protected property The messenger. 27
MessengerTrait::messenger public function Gets the messenger. 27
MessengerTrait::setMessenger public function Sets the messenger.
RedirectDestinationTrait::$redirectDestination protected property The redirect destination service. 1
RedirectDestinationTrait::getDestinationArray protected function Prepares a 'destination' URL query parameter for use with \Drupal\Core\Url.
RedirectDestinationTrait::getRedirectDestination protected function Returns the redirect destination service.
RedirectDestinationTrait::setRedirectDestination public function Sets the redirect destination service.
SocialProfileFieldsFlushForm::$configFactory protected property Configstorage. Overrides FormBase::$configFactory
SocialProfileFieldsFlushForm::$fieldStorage protected property Fiekdconfigstorage.
SocialProfileFieldsFlushForm::$profileStorage protected property Profilestorage.
SocialProfileFieldsFlushForm::create public static function Instantiates a new instance of this class. Overrides FormBase::create
SocialProfileFieldsFlushForm::getCancelUrl public function Returns the route to go to if the user cancels the action. Overrides ConfirmFormInterface::getCancelUrl
SocialProfileFieldsFlushForm::getConfirmText public function Returns a caption for the button that confirms the action. Overrides ConfirmFormBase::getConfirmText
SocialProfileFieldsFlushForm::getDescription public function Returns additional text to display as a description. Overrides ConfirmFormBase::getDescription
SocialProfileFieldsFlushForm::getFormId public function Returns a unique string identifying the form. Overrides FormInterface::getFormId
SocialProfileFieldsFlushForm::getQuestion public function Returns the question to ask the user. Overrides ConfirmFormInterface::getQuestion
SocialProfileFieldsFlushForm::getUnselectedFields protected function Function that return an array of field names.
SocialProfileFieldsFlushForm::submitForm public function Form submission handler. Overrides FormInterface::submitForm
SocialProfileFieldsFlushForm::__construct public function Constructs a new ExportUserConfirm.
StringTranslationTrait::$stringTranslation protected property The string translation service. 4
StringTranslationTrait::formatPlural protected function Formats a string containing a count of items.
StringTranslationTrait::getNumberOfPlurals protected function Returns the number of plurals supported by a given language.
StringTranslationTrait::getStringTranslation protected function Gets the string translation service.
StringTranslationTrait::setStringTranslation public function Sets the string translation service to use. 2
StringTranslationTrait::t protected function Translates a string to the current language or to a given language.