function potx_status in Translation template extractor 8
Same name and namespace in other branches
- 6.3 potx.inc \potx_status()
- 6.2 potx.inc \potx_status()
- 7.3 potx.inc \potx_status()
- 7 potx.inc \potx_status()
- 7.2 potx.inc \potx_status()
Status notification function.
Parameters
string $op: Operation to perform or type of message text.
- set: sets the reporting mode to $value use one of the POTX_STATUS_* constants as $value
- get: returns the list of error messages recorded if $value is true, it also clears the internal message cache
- error: sends an error message in $value with optional $file and $line
- status: sends a status message in $value.
mixed $value: Value depending on $op.
string $file: Name of file the error message is related to.
int $line: Number of line the error message is related to.
string $excerpt: Excerpt of the code in question, if available.
string $docs_url: URL to the guidelines to follow to fix the problem.
16 calls to potx_status()
- PotxCommands::potx in src/
Commands/ PotxCommands.php - Extract translatable strings from Drupal source code.
- PotxExtractTranslationForm::submitForm in src/
Form/ PotxExtractTranslationForm.php - Form submission handler.
- PotxTest::buildOutput in tests/
src/ Kernel/ PotxTest.php - Build the output from parsed files.
- PotxTest::parseFile in tests/
src/ Kernel/ PotxTest.php - Parse the given file with the given API version.
- PotxTest::parsePhpContent in tests/
src/ Kernel/ PotxTest.php - Parse the given file with the given API version.
File
- ./
potx.inc, line 893 - Extraction API used by the web and command line interface.
Code
function potx_status($op, $value = NULL, $file = NULL, $line = NULL, $excerpt = NULL, $docs_url = NULL) {
static $mode = POTX_STATUS_CLI;
static $messages = [];
switch ($op) {
case 'set':
// Setting the reporting mode.
$mode = $value;
return;
case 'get':
// Getting the errors. Optionally deleting the messages.
$errors = $messages;
if (!empty($value)) {
$messages = [];
}
return $errors;
case 'error':
case 'status':
// Location information is required in 3 of the four possible reporting
// modes as part of the error message. The structured mode needs the
// file, line and excerpt info separately, not in the text.
$location_info = '';
if ($mode != POTX_STATUS_STRUCTURED && isset($file)) {
if (isset($line)) {
if (isset($excerpt)) {
$location_info = t('At %excerpt in %file on line %line.', [
'%excerpt' => $excerpt,
'%file' => $file,
'%line' => $line,
]);
}
else {
$location_info = t('In %file on line %line.', [
'%file' => $file,
'%line' => $line,
]);
}
}
else {
if (isset($excerpt)) {
$location_info = t('At %excerpt in %file.', [
'%excerpt' => $excerpt,
'%file' => $file,
]);
}
else {
$location_info = t('In %file.', [
'%file' => $file,
]);
}
}
}
// Documentation helpers are provided as readable text in most modes.
$read_more = '';
if ($mode != POTX_STATUS_STRUCTURED && isset($docs_url)) {
$read_more = $mode == POTX_STATUS_CLI ? t('Read more at @url', [
'@url' => $docs_url,
]) : t('Read more at <a href="@url">@url</a>', [
'@url' => $docs_url,
]);
}
// Error message or progress text to display.
switch ($mode) {
case POTX_STATUS_MESSAGE:
\Drupal::messenger()
->addMessage(t('@value @location_info @read_more', [
'@value' => $value,
'@location_info' => $location_info,
'@read_more' => $read_more,
]), $op);
break;
case POTX_STATUS_CLI:
fwrite($op == 'error' ? STDERR : STDOUT, implode("\n", [
$value,
$location_info,
$read_more,
]) . "\n\n");
break;
case POTX_STATUS_SILENT:
if ($op == 'error') {
$messages[] = implode(' ', [
$value,
$location_info,
$read_more,
]);
}
break;
case POTX_STATUS_STRUCTURED:
if ($op == 'error') {
$messages[] = [
$value,
$file,
$line,
$excerpt,
$docs_url,
];
}
break;
}
return;
}
}