class ClientsideValidationJqueryDrush in Clientside Validation 3.0.x
Drush command file for clientside_validation_jquery module.
It exposes drush commands to manage the required jquery validation library.
Hierarchy
- class \Drupal\clientside_validation_jquery\Commands\ClientsideValidationJqueryDrush extends \Drush\Commands\DrushCommands
Expanded class hierarchy of ClientsideValidationJqueryDrush
1 string reference to 'ClientsideValidationJqueryDrush'
- drush.services.yml in clientside_validation_jquery/
drush.services.yml - clientside_validation_jquery/drush.services.yml
1 service uses ClientsideValidationJqueryDrush
- clientside_validation_jquery.commands in clientside_validation_jquery/
drush.services.yml - Drupal\clientside_validation_jquery\Commands\ClientsideValidationJqueryDrush
File
- clientside_validation_jquery/
src/ Commands/ ClientsideValidationJqueryDrush.php, line 15
Namespace
Drupal\clientside_validation_jquery\CommandsView source
class ClientsideValidationJqueryDrush extends DrushCommands {
/**
* Service for accessing filesystem.
*
* @var \Drupal\Core\File\FileSystemInterface
*/
protected $fileSystem;
/**
* ClientsideValidationJqueryDrush Constructor.
*
* @param \Drupal\Core\File\FileSystemInterface $file_system
* Service for accessing filesystem.
*/
public function __construct(FileSystemInterface $file_system) {
$this->fileSystem = $file_system;
}
/**
* Show the status of library required by clientside validation jQuery module.
*
* @command clientside_validation_jquery:library-status
* @aliases cvjls
*/
public function libraryStatus() {
$installed = file_exists(DRUPAL_ROOT . '/libraries/jquery-validation/dist/jquery.validate.js');
$message = $installed ? 'installed' : 'not installed';
$this
->logger()
->notice('Library required for clientside validation jQuery is {message}', [
'message' => $message,
]);
}
/**
* Download third party libraries required by clientside validation jQuery module.
*
* @command clientside_validation_jquery:library-download
* @aliases cvjld
*/
public function addLibrary() {
// Check if library is already available.
if (file_exists(DRUPAL_ROOT . '/libraries/jquery-validation')) {
throw new \Exception('Library already downloaded, if you want to download again, please remove it first.');
}
// Download library.
$tmp_location = $this->fileSystem
->getTempDirectory();
$download_url = 'https://github.com/jquery-validation/jquery-validation/archive/1.17.0.zip';
$this
->logger()
->notice('Downloading {download_url}', [
'download_url' => $download_url,
]);
file_put_contents($tmp_location . '/jquery-validation.zip', fopen($download_url, 'r'));
$path = $tmp_location . '/jquery-validation.zip';
$destination = DRUPAL_ROOT . '/libraries';
// Unzip the downloaded archive.
$process = Drush::process([
'unzip',
$path,
'-d',
$destination,
]);
$process
->run();
$return = $process
->isSuccessful();
if (!$return) {
throw new \Exception(dt('Unable to extract !filename.' . PHP_EOL . implode(PHP_EOL, $process
->getOutput()), [
'!filename' => $path,
]));
}
// Name it properly (remove version number from directory).
$fs = new Filesystem();
$fs
->rename(DRUPAL_ROOT . '/libraries/jquery-validation-1.17.0', DRUPAL_ROOT . '/libraries/jquery-validation', TRUE);
// Flush all caches.
drupal_flush_all_caches();
}
/**
* Remove third party libraries required by clientside validation jQuery module.
*
* @command clientside_validation_jquery:library-remove
* @aliases cvjlr
*/
public function removeLibrary() {
$this
->logger()
->notice('Beginning to remove libraries...');
if (file_exists(DRUPAL_ROOT . '/libraries/jquery-validation')) {
$this
->logger()
->notice('jQuery validation library removed.');
$this->fileSystem
->deleteRecursive(DRUPAL_ROOT . '/libraries/jquery-validation');
drupal_flush_all_caches();
return TRUE;
}
return FALSE;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ClientsideValidationJqueryDrush:: |
protected | property | Service for accessing filesystem. | |
ClientsideValidationJqueryDrush:: |
public | function | Download third party libraries required by clientside validation jQuery module. | |
ClientsideValidationJqueryDrush:: |
public | function | Show the status of library required by clientside validation jQuery module. | |
ClientsideValidationJqueryDrush:: |
public | function | Remove third party libraries required by clientside validation jQuery module. | |
ClientsideValidationJqueryDrush:: |
public | function | ClientsideValidationJqueryDrush Constructor. |