本文整理汇总了PHP中Craft\Craft::t方法的典型用法代码示例。如果您正苦于以下问题:PHP Craft::t方法的具体用法?PHP Craft::t怎么用?PHP Craft::t使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Craft\Craft
的用法示例。
在下文中一共展示了Craft::t方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: doDisplay
protected function doDisplay(array $context, array $blocks = array())
{
// line 1
$context["forms"] = $this->env->loadTemplate("_includes/forms");
// line 2
echo "\n\n";
// line 4
echo $context["forms"]->gettextField(array("label" => \Craft\Craft::t("Placeholder Text"), "instructions" => \Craft\Craft::t("The text that will be shown if the field doesn’t have a value."), "id" => "placeholder", "name" => "placeholder", "value" => $this->getAttribute($this->getContext($context, "settings"), "placeholder"), "translatable" => true, "errors" => $this->getAttribute($this->getContext($context, "settings"), "getErrors", array(0 => "placeholder"), "method")));
// line 12
echo "\n\n";
// line 14
echo $context["forms"]->gettextField(array("label" => \Craft\Craft::t("Max Length"), "instructions" => \Craft\Craft::t("The maximum length of characters the field is allowed to have."), "id" => "maxLength", "name" => "maxLength", "value" => $this->getAttribute($this->getContext($context, "settings"), "maxLength"), "size" => 3, "errors" => $this->getAttribute($this->getContext($context, "settings"), "getErrors", array(0 => "maxLength"), "method")));
// line 22
echo "\n\n";
// line 24
echo $context["forms"]->getcheckboxField(array("label" => \Craft\Craft::t("Allow line breaks"), "name" => "multiline", "checked" => $this->getAttribute($this->getContext($context, "settings"), "multiline"), "toggle" => "initialRowsContainer"));
// line 29
echo "\n\n\n<div id=\"initialRowsContainer\" class=\"nested-fields";
// line 32
if (!$this->getAttribute($this->getContext($context, "settings"), "multiline")) {
echo " hidden";
}
echo "\">\n\t";
// line 33
echo $context["forms"]->gettextField(array("label" => \Craft\Craft::t("Initial Rows"), "id" => "initialRows", "name" => "initialRows", "value" => $this->getAttribute($this->getContext($context, "settings"), "initialRows"), "size" => 3, "errors" => $this->getAttribute($this->getContext($context, "settings"), "getErrors", array(0 => "initialRows"), "method")));
// line 40
echo "\n</div>\n";
}
开发者ID:scisahaha,项目名称:generator-craft,代码行数:28,代码来源:008a8f3123ede362a4b694b692faff97ed3826b5f10db619eea237abd6e7.php
示例2: sortByFieldFilter
/**
* The "sortByField" filter sorts an array of entries by the specified field's value
*
* Usage: {% for entry in craft.entries|sortByField('ordering', 'desc') %}
*/
public function sortByFieldFilter($content, $sort_by = null, $direction = 'asc')
{
if (!is_array($content)) {
throw new Exception(Craft::t('Variable passed to the sortByField filter is not an array'));
} elseif (!(isset($content[0]) && is_object($content[0]) && (get_class($content[0]) === 'Craft\\EntryModel' || get_class($content[0]) === 'Craft\\Commerce_ProductModel'))) {
throw new Exception(Craft::t('Variables passed to the sortByField filter are not entries'));
} elseif ($sort_by === null) {
throw new Exception(Craft::t('No sort by parameter passed to the sortByField filter'));
} elseif (!$content[0]->__isset($sort_by)) {
throw new Exception(Craft::t('Entries passed to the sortByField filter do not have the field "' . $sort_by . '"'));
} else {
// Unfortunately have to suppress warnings here due to __get function
// causing usort to think that the array has been modified:
// usort(): Array was modified by the user comparison function
@usort($content, function ($a, $b) use($sort_by, $direction) {
$flip = $direction === 'desc' ? -1 : 1;
$a_sort_value = $a->__get($sort_by);
$b_sort_value = $b->__get($sort_by);
if ($a_sort_value == $b_sort_value) {
return 0;
} else {
if ($a_sort_value > $b_sort_value) {
return 1 * $flip;
} else {
return -1 * $flip;
}
}
});
}
return $content;
}
示例3: InfiniteScrollFilter
public function InfiniteScrollFilter($paginate, $containerSelector = null, $itemSelector = null, $loadingMessage = null, $loadingImage = null, $finishedMessage = null)
{
if (!$containerSelector || !$itemSelector) {
return null;
}
$content = '';
if ($paginate->getNextUrl()) {
$content .= '<div class="infinite-pagination"><a href="' . $paginate->getNextUrl() . '">' . Craft::t('Next Page') . '</a></div>';
}
$content .= craft()->templates->includeJsResource('infinitescroll/js/jquery.infinitescroll.min.js');
$script = 'var totalNumOfPages = ' . $paginate->totalPages . ';';
$script .= 'var containerSelector = "' . $containerSelector . '";';
$script .= 'var itemSelector = "' . $itemSelector . '";';
$loadingImage = $loadingImage ? $loadingImage : UrlHelper::getResourceUrl('infinitescroll/img/ajax-loader.gif');
$script .= 'var loadingImage = "' . $loadingImage . '";';
if ($loadingMessage) {
$script .= 'var loadingMessage = "' . $loadingMessage . '";';
}
if ($finishedMessage) {
$script .= 'var finishedMessage = "' . $finishedMessage . '";';
}
$content .= craft()->templates->includeJs($script);
$content .= craft()->templates->includeJsResource('infinitescroll/js/infinitescroll.js');
return $content;
}
示例4: _validateoptions
private function _validateoptions($options)
{
if (empty($options)) {
throw new Exception(Craft::t('vCard Parameters must be supplied'));
}
return true;
}
示例5: actionIndex
/**
* Exports the Craft datamodel.
*
* @param string $file file to write the schema to
* @param array $exclude Data to not export
*
* @return int
*/
public function actionIndex($file = 'craft/config/schema.yml', array $exclude = null)
{
$dataTypes = Schematic::getExportableDataTypes();
// If there are data exclusions.
if ($exclude !== null) {
// Find any invalid data to exclude.
$invalidExcludes = array_diff($exclude, $dataTypes);
// If any invalid exclusions were specified.
if (count($invalidExcludes) > 0) {
$errorMessage = 'Invalid exlude';
if (count($invalidExcludes) > 1) {
$errorMessage .= 's';
}
$errorMessage .= ': ' . implode(', ', $invalidExcludes) . '.';
$errorMessage .= ' Valid exclusions are ' . implode(', ', $dataTypes);
// Output an error message outlining what invalid exclusions were specified.
echo "\n" . $errorMessage . "\n\n";
return 1;
}
// Remove any explicitly excluded data types from the list of data types to export.
$dataTypes = array_diff($dataTypes, $exclude);
}
Craft::app()->schematic->exportToYaml($file, $dataTypes);
Craft::log(Craft::t('Exported schema to {file}', ['file' => $file]));
return 0;
}
示例6: fire
/**
* {@inheritdoc}
*/
protected function fire()
{
$caches = '*';
$tool = craft()->components->getComponentByTypeAndClass(ComponentType::Tool, 'ClearCaches');
if ($this->option('select')) {
$reflectionMethod = new ReflectionMethod($tool, '_getFolders');
$reflectionMethod->setAccessible(true);
$values = $reflectionMethod->invoke($tool);
$values['assetTransformIndex'] = Craft::t('Asset transform index');
$values['assetIndexingData'] = Craft::t('Asset indexing data');
$values['templateCaches'] = Craft::t('Template caches');
$keys = array_keys($values);
$options = array_values($values);
$dialog = $this->getHelper('dialog');
$selected = $dialog->select($this->output, 'Select which caches to clear (separate multiple by comma)', $options, null, false, 'Value "%s" is invalid', true);
$caches = array();
foreach ($selected as $index) {
$caches[] = $keys[$index];
}
}
$this->suppressOutput(function () use($tool, $caches) {
$tool->performAction(compact('caches'));
});
$this->info('Cache(s) cleared.');
}
示例7: save
/**
* @param Market_OrderStatusModel $model
* @param array $emailsIds
*
* @return bool
* @throws Exception
* @throws \CDbException
* @throws \Exception
*/
public function save(Market_OrderStatusModel $model, array $emailsIds)
{
if ($model->id) {
$record = Market_OrderStatusRecord::model()->findById($model->id);
if (!$record->id) {
throw new Exception(Craft::t('No order status exists with the ID “{id}”', ['id' => $model->id]));
}
} else {
$record = new Market_OrderStatusRecord();
}
$record->name = $model->name;
$record->handle = $model->handle;
$record->color = $model->color;
$record->default = $model->default;
$record->validate();
$model->addErrors($record->getErrors());
//validating emails ids
$criteria = new \CDbCriteria();
$criteria->addInCondition('id', $emailsIds);
$exist = Market_EmailRecord::model()->exists($criteria);
$hasEmails = (bool) count($emailsIds);
if (!$exist && $hasEmails) {
$model->addError('emails', 'One or more emails do not exist in the system.');
}
//saving
if (!$model->hasErrors()) {
MarketDbHelper::beginStackedTransaction();
try {
//only one default status can be among statuses of one order type
if ($record->default) {
Market_OrderStatusRecord::model()->updateAll(['default' => 0]);
}
// Save it!
$record->save(false);
//Delete old links
if ($model->id) {
Market_OrderStatusEmailRecord::model()->deleteAllByAttributes(['orderStatusId' => $model->id]);
}
//Save new links
$rows = array_map(function ($id) use($record) {
return [$id, $record->id];
}, $emailsIds);
$cols = ['emailId', 'orderStatusId'];
$table = Market_OrderStatusEmailRecord::model()->getTableName();
craft()->db->createCommand()->insertAll($table, $cols, $rows);
// Now that we have a calendar ID, save it on the model
$model->id = $record->id;
MarketDbHelper::commitStackedTransaction();
} catch (\Exception $e) {
MarketDbHelper::rollbackStackedTransaction();
throw $e;
}
return true;
} else {
return false;
}
}
示例8: export
/**
* @param array $data
*
* @return array
*/
public function export(array $data = [])
{
Craft::log(Craft::t('Exporting Locales'));
$locales = $this->getLocalizationService()->getSiteLocales();
$localeDefinitions = [];
foreach ($locales as $locale) {
$localeDefinitions[] = $locale->getId();
}
return $localeDefinitions;
}
示例9: initMarketNav
/**
* Temporary nav until 2.5 is released.
*/
private function initMarketNav()
{
if (craft()->request->isCpRequest()) {
craft()->templates->includeCssResource('market/market-nav.css');
craft()->templates->includeJsResource('market/market-nav.js');
$nav = [['url' => 'market/orders', 'title' => Craft::t("Orders"), 'selected' => craft()->request->getSegment(2) == 'orders' ? true : false], ['url' => 'market/products', 'title' => Craft::t("Products"), 'selected' => craft()->request->getSegment(2) == 'products' ? true : false], ['url' => 'market/promotions', 'title' => Craft::t("Promotions"), 'selected' => craft()->request->getSegment(2) == 'promotions' ? true : false], ['url' => 'market/customers', 'title' => Craft::t("Customers"), 'selected' => craft()->request->getSegment(2) == 'customers' ? true : false], ['url' => 'market/settings', 'title' => Craft::t("Settings"), 'selected' => craft()->request->getSegment(2) == 'settings' ? true : false]];
$navJson = JsonHelper::encode($nav);
craft()->templates->includeJs('new Craft.MarketNav(' . $navJson . ');');
}
}
示例10: testRowShouldLogErrorWhenColumnsAndDataDoNotMatch
/**
* @covers ::row
*/
public function testRowShouldLogErrorWhenColumnsAndDataDoNotMatch()
{
$row = 1;
$historyId = 2;
$settings = array('map' => array('column1', 'column2', 'column3'), 'history' => $historyId);
$data = array('row1value1', 'row2', 'value2', 'row3value3');
$message = array(array(Craft::t('Columns and data did not match, could be due to malformed CSV row.')));
$this->setMockImportHistoryService($historyId, $row, $message);
$service = new ImportService();
$service->row($row, $data, $settings);
}
示例11: doDisplay
protected function doDisplay(array $context, array $blocks = array())
{
// line 1
$context["__internal_8bc6326091755a7238d5805374fab8e110743b6ddea9106be2b518883cdf1153"] = $this->env->loadTemplate("_includes/forms");
// line 2
echo "\n";
// line 3
echo $context["__internal_8bc6326091755a7238d5805374fab8e110743b6ddea9106be2b518883cdf1153"]->gettextField(array("label" => \Craft\Craft::t($this->getAttribute($this->getAttribute($this->getContext($context, "entry"), "getType", array(), "method"), "titleLabel")), "id" => "title", "name" => "title", "value" => $this->getAttribute($this->getContext($context, "entry"), "title"), "errors" => $this->getAttribute($this->getContext($context, "entry"), "getErrors", array(0 => "title"), "method"), "first" => true, "autofocus" => true, "required" => true));
// line 12
echo "\n";
}
开发者ID:scisahaha,项目名称:generator-craft,代码行数:11,代码来源:f353b796cc9c79b14483d0a236e1f3b1310b46a6cf1b358754944b6dd144.php
示例12: getColorPalette
/**
* Gets color palette for image
*
* @param AssetFileModel|string $image
* @param $colorCount
* @param $quality
* @param $colorValue
* @return array
* @throws Exception
*/
public function getColorPalette($image, $colorCount, $quality, $colorValue)
{
$pathsModel = new Imager_ImagePathsModel($image);
if (!IOHelper::getRealPath($pathsModel->sourcePath)) {
throw new Exception(Craft::t('Source folder “{sourcePath}” does not exist', array('sourcePath' => $pathsModel->sourcePath)));
}
if (!IOHelper::fileExists($pathsModel->sourcePath . $pathsModel->sourceFilename)) {
throw new Exception(Craft::t('Requested image “{fileName}” does not exist in path “{sourcePath}”', array('fileName' => $pathsModel->sourceFilename, 'sourcePath' => $pathsModel->sourcePath)));
}
$palette = ColorThief::getPalette($pathsModel->sourcePath . $pathsModel->sourceFilename, $colorCount, $quality);
return $colorValue == 'hex' ? $this->_paletteToHex($palette) : $palette;
}
示例13: init
public function init()
{
$parcelType = $this;
$this->craft()->on('email.beforeSendEmail', function (Event $event) use($parcelType) {
if ($parcelType->parcel->service->is('craft')) {
throw new \Craft\Exception(\Craft\Craft::t('You cannot override Craft system emails and use the Craft Postmaster service. To fix this error, edit your system email parcel and change the service to something other than Craft. If you cannot edit parcels in Postmaster or have no idea what a parcel or Postmaster is, it\'s probably best to contact your site administrator'));
}
$event->performAction = false;
$parcelType->parse($event->params);
$obj = new Postmaster_TransportModel(array('service' => $parcelType->parcel->service, 'settings' => $parcelType->settings, 'data' => $event->params));
$parcelType->parcel->send($obj);
});
}
示例14: actionIndex
/**
* Imports the Craft datamodel.
*
* @param string $file yml file containing the schema definition
* @param string $override_file yml file containing the override values
* @param bool $force if set to true items not in the import will be deleted
*
* @return int
*/
public function actionIndex($file = 'craft/config/schema.yml', $override_file = 'craft/config/override.yml', $force = false)
{
if (!IOHelper::fileExists($file)) {
$this->usageError(Craft::t('File not found.'));
}
$result = Craft::app()->schematic->importFromYaml($file, $override_file, $force);
if (!$result->hasErrors()) {
Craft::log(Craft::t('Loaded schema from {file}', ['file' => $file]));
return 0;
}
Craft::log(Craft::t('There was an error loading schema from {file}', ['file' => $file]));
print_r($result->getErrors());
return 1;
}
示例15: doDisplay
protected function doDisplay(array $context, array $blocks = array())
{
// line 1
$context["allLabel"] = array_key_exists("allLabel", $context) ? $this->getContext($context, "allLabel") : \Craft\Craft::t("All");
// line 2
$context["allValue"] = array_key_exists("allValue", $context) ? $this->getContext($context, "allValue") : "*";
// line 3
$context["options"] = array_key_exists("options", $context) ? $this->getContext($context, "options") : array();
// line 4
$context["values"] = array_key_exists("values", $context) ? $this->getContext($context, "values") : array();
// line 5
$context["allChecked"] = twig_test_empty($this->getContext($context, "values")) || $this->getContext($context, "values") == $this->getContext($context, "allValue");
// line 6
echo "\n<div class=\"checkbox-select";
// line 7
if (array_key_exists("class", $context)) {
echo " ";
echo twig_escape_filter($this->env, $this->getContext($context, "class"), "html", null, true);
}
echo "\">\n\t<div>\n\t\t";
// line 9
$this->env->loadTemplate("_includes/forms/checkbox")->display(array("id" => array_key_exists("id", $context) ? $this->getContext($context, "id") : null, "class" => "all", "label" => "<b>" . (array_key_exists("allLabel", $context) ? $this->getContext($context, "allLabel") : \Craft\Craft::t("All")) . "</b>", "name" => array_key_exists("name", $context) ? $this->getContext($context, "name") : null, "value" => $this->getContext($context, "allValue"), "checked" => $this->getContext($context, "allChecked"), "autofocus" => array_key_exists("autofocus", $context) && $this->getContext($context, "autofocus") && !$this->getAttribute($this->getAttribute($this->getContext($context, "craft"), "request"), "isMobileBrowser", array(0 => true), "method")));
// line 18
echo "\t</div>";
// line 19
$context['_parent'] = (array) $context;
$context['_seq'] = twig_ensure_traversable($this->getContext($context, "options"));
foreach ($context['_seq'] as $context["key"] => $context["option"]) {
// line 20
$context["optionLabel"] = $this->getAttribute($this->getContext($context, "option", true), "label", array(), "any", true, true) ? $this->getAttribute($this->getContext($context, "option"), "label") : $this->getContext($context, "option");
// line 21
$context["optionValue"] = $this->getAttribute($this->getContext($context, "option", true), "value", array(), "any", true, true) ? $this->getAttribute($this->getContext($context, "option"), "value") : $this->getContext($context, "key");
// line 22
if ($this->getContext($context, "optionValue") != $this->getContext($context, "allValue")) {
// line 23
echo "\t\t\t<div>\n\t\t\t\t";
// line 24
$this->env->loadTemplate("_includes/forms/checkbox")->display(array("label" => $this->getContext($context, "optionLabel"), "name" => array_key_exists("name", $context) ? $this->getContext($context, "name") . "[]" : null, "value" => $this->getContext($context, "optionValue"), "checked" => $this->getContext($context, "allChecked") || twig_in_filter($this->getContext($context, "optionValue"), $this->getContext($context, "values")), "disabled" => $this->getContext($context, "allChecked")));
// line 31
echo "\t\t\t</div>\n\t\t";
}
// line 33
echo "\t";
}
$_parent = $context['_parent'];
unset($context['_seq'], $context['_iterated'], $context['key'], $context['option'], $context['_parent'], $context['loop']);
$context = array_intersect_key($context, $_parent) + $_parent;
// line 34
echo "</div>\n";
}
开发者ID:scisahaha,项目名称:generator-craft,代码行数:50,代码来源:f4e1a9ef3957d6b7fdb7f6f15af0cbc14d9e33ef7b22fb9a43bb69ada1f4.php