本文整理汇总了PHP中Magento\Framework\Escaper::escapeHtml方法的典型用法代码示例。如果您正苦于以下问题:PHP Escaper::escapeHtml方法的具体用法?PHP Escaper::escapeHtml怎么用?PHP Escaper::escapeHtml使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Magento\Framework\Escaper
的用法示例。
在下文中一共展示了Escaper::escapeHtml方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testEmulateWelcomeBlock
/**
* @magentoConfigFixture current_store persistent/options/enabled 1
* @magentoConfigFixture current_store persistent/options/remember_enabled 1
* @magentoConfigFixture current_store persistent/options/remember_default 1
* @magentoAppArea frontend
* @magentoAppIsolation enabled
*/
public function testEmulateWelcomeBlock()
{
$this->_customerSession->loginById(1);
$httpContext = new \Magento\Framework\App\Http\Context();
$httpContext->setValue(Context::CONTEXT_AUTH, 1, 1);
$block = $this->_objectManager->create('Magento\\Sales\\Block\\Reorder\\Sidebar', ['httpContext' => $httpContext]);
$this->_observer->emulateWelcomeBlock($block);
$customerName = $this->_escaper->escapeHtml($this->_customerViewHelper->getCustomerName($this->customerRepository->getById($this->_persistentSessionHelper->getSession()->getCustomerId())));
$translation = __('Welcome, %1!', $customerName);
$this->assertStringMatchesFormat('%A' . $translation . '%A', $block->getWelcome());
$this->_customerSession->logout();
}
示例2: execute
/**
* Register form key in session from cookie value
*
* @return void
*/
public function execute()
{
$formKeyFromCookie = $this->_formKey->get();
if ($formKeyFromCookie) {
$this->_session->setData(\Magento\Framework\Data\Form\FormKey::FORM_KEY, $this->_escaper->escapeHtml($formKeyFromCookie));
}
}
示例3: prepareItem
/**
* Get data
*
* @param array $item
* @return string
*/
protected function prepareItem(array $item)
{
$content = '';
$origStores = $item['store_id'];
if (empty($origStores)) {
return '';
}
if (!is_array($origStores)) {
$origStores = [$origStores];
}
if (in_array(0, $origStores) && count($origStores) == 1) {
return __('All Store Views');
}
$data = $this->systemStore->getStoresStructure(false, $origStores);
foreach ($data as $website) {
$content .= $website['label'] . "<br/>";
foreach ($website['children'] as $group) {
$content .= str_repeat(' ', 3) . $this->escaper->escapeHtml($group['label']) . "<br/>";
foreach ($group['children'] as $store) {
$content .= str_repeat(' ', 6) . $this->escaper->escapeHtml($store['label']) . "<br/>";
}
}
}
return $content;
}
示例4: execute
/**
* Forgot customer password action
*
* @return \Magento\Framework\Controller\Result\Redirect
*/
public function execute()
{
/** @var \Magento\Framework\Controller\Result\Redirect $resultRedirect */
$resultRedirect = $this->resultRedirectFactory->create();
$email = (string) $this->getRequest()->getPost('email');
if ($email) {
if (!\Zend_Validate::is($email, 'EmailAddress')) {
$this->_getSession()->setForgottenEmail($email);
$this->messageManager->addError(__('Please correct the email address.'));
$resultRedirect->setPath('*/*/forgotpassword');
return $resultRedirect;
}
try {
$this->customerAccountManagement->initiatePasswordReset($email, AccountManagement::EMAIL_RESET);
} catch (NoSuchEntityException $e) {
// Do nothing, we don't want anyone to use this action to determine which email accounts are registered.
} catch (\Exception $exception) {
$this->messageManager->addException($exception, __('Unable to send password reset email.'));
$resultRedirect->setPath('*/*/forgotpassword');
return $resultRedirect;
}
$email = $this->escaper->escapeHtml($email);
// @codingStandardsIgnoreStart
$this->messageManager->addSuccess(__('If there is an account associated with %1 you will receive an email with a link to reset your password.', $email));
// @codingStandardsIgnoreEnd
$resultRedirect->setPath('*/*/');
return $resultRedirect;
} else {
$this->messageManager->addError(__('Please enter your email.'));
$resultRedirect->setPath('*/*/forgotpassword');
return $resultRedirect;
}
}
示例5: execute
/**
* Register form key in session from cookie value
*
* @param \Magento\Framework\Event\Observer $observer
* @return void
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function execute(\Magento\Framework\Event\Observer $observer)
{
if ($this->cookieFormKey->get()) {
$this->updateCookieFormKey($this->cookieFormKey->get());
$this->sessionFormKey->set($this->escaper->escapeHtml($this->cookieFormKey->get()));
}
}
示例6: execute
/**
* Add shared wishlist item to shopping cart
*
* If Product has required options - redirect
* to product view page with message about needed defined required options
*
* @return \Magento\Framework\Controller\Result\Redirect
*/
public function execute()
{
$itemId = (int) $this->getRequest()->getParam('item');
/* @var $item Item */
$item = $this->itemFactory->create()->load($itemId);
$redirectUrl = $this->_redirect->getRefererUrl();
try {
/** @var OptionCollection $options */
$options = $this->optionFactory->create()->getCollection()->addItemFilter([$itemId]);
$item->setOptions($options->getOptionsByItem($itemId));
$item->addToCart($this->cart);
$this->cart->save();
if (!$this->cart->getQuote()->getHasError()) {
$message = __('You added %1 to your shopping cart.', $this->escaper->escapeHtml($item->getProduct()->getName()));
$this->messageManager->addSuccess($message);
}
if ($this->cartHelper->getShouldRedirectToCart()) {
$redirectUrl = $this->cartHelper->getCartUrl();
}
} catch (ProductException $e) {
$this->messageManager->addError(__('This product(s) is out of stock.'));
} catch (LocalizedException $e) {
$this->messageManager->addNotice($e->getMessage());
$redirectUrl = $item->getProductUrl();
} catch (\Exception $e) {
$this->messageManager->addException($e, __('We can\'t add the item to the cart right now.'));
}
/** @var \Magento\Framework\Controller\Result\Redirect $resultRedirect */
$resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);
$resultRedirect->setUrl($redirectUrl);
return $resultRedirect;
}
示例7: getTitle
/**
* get toooltip title
*
* @param bool $escaped
* @return string
*/
public function getTitle($escaped = true)
{
if ($escaped) {
return $this->escaper->escapeHtml($this->title);
}
return $this->title;
}
示例8: generateCurrentOptions
/**
* Generate current options
*
* @return void
*/
protected function generateCurrentOptions()
{
$websiteCollection = $this->systemStore->getWebsiteCollection();
$groupCollection = $this->systemStore->getGroupCollection();
$storeCollection = $this->systemStore->getStoreCollection();
/** @var \Magento\Store\Model\Website $website */
foreach ($websiteCollection as $website) {
$groups = [];
/** @var \Magento\Store\Model\Group $group */
foreach ($groupCollection as $group) {
if ($group->getWebsiteId() == $website->getId()) {
$stores = [];
/** @var \Magento\Store\Model\Store $store */
foreach ($storeCollection as $store) {
if ($store->getGroupId() == $group->getId()) {
$name = $this->escaper->escapeHtml($store->getName());
$stores[$name]['label'] = str_repeat(' ', 8) . $name;
$stores[$name]['value'] = $store->getId();
}
}
if (!empty($stores)) {
$name = $this->escaper->escapeHtml($group->getName());
$groups[$name]['label'] = str_repeat(' ', 4) . $name;
$groups[$name]['value'] = array_values($stores);
}
}
}
if (!empty($groups)) {
$name = $this->escaper->escapeHtml($website->getName());
$this->currentOptions[$name]['label'] = $name;
$this->currentOptions[$name]['value'] = array_values($groups);
}
}
}
示例9: emulateWelcomeBlock
/**
* Emulate 'welcome' block with persistent data
*
* @param \Magento\Framework\View\Element\AbstractBlock $block
* @return $this
*/
public function emulateWelcomeBlock($block)
{
$escapedName = $this->_escaper->escapeHtml($this->_customerViewHelper->getCustomerName($this->customerRepository->getById($this->_persistentSession->getSession()->getCustomerId())), null);
$this->_applyAccountLinksPersistentData();
$welcomeMessage = __('Welcome, %1!', $escapedName) . ' ' . $this->_layout->getBlock('header.additional')->toHtml();
$block->setWelcome($welcomeMessage);
return $this;
}
示例10: prepareDataSource
/**
* Prepare Data Source
*
* @param array $dataSource
* @return array
*/
public function prepareDataSource(array $dataSource)
{
if (isset($dataSource['data']['items'])) {
foreach ($dataSource['data']['items'] as &$item) {
$item[$this->getData('name')] = $this->escaper->escapeHtml(str_replace("\n", '<br/>', $item[$this->getData('name')]));
}
}
return $dataSource;
}
示例11: process
/**
* {@inheritdoc}
*/
public function process($jsLayout)
{
$agreementConfiguration = [];
$agreementsList = $this->checkoutAgreementsRepository->getList();
foreach ($agreementsList as $agreement) {
$agreementConfiguration[] = ['content' => $agreement->getIsHtml() ? $agreement->getContent() : nl2br($this->escaper->escapeHtml($agreement->getContent())), 'height' => $agreement->getContentHeight(), 'checkboxText' => $agreement->getCheckboxText()];
}
$jsLayout['components']['checkout']['children']['steps']['children']['billing-step']['children']['payment']['children']['payments-list']['children']['before-place-order']['children']['checkout-agreements-modal']['config']['agreementConfiguration'] = $agreementConfiguration;
return $jsLayout;
}
示例12: getAgreementsConfig
/**
* Returns agreements config
*
* @return array
*/
protected function getAgreementsConfig()
{
$agreementConfiguration = [];
$isAgreementsEnabled = $this->scopeConfiguration->isSetFlag(AgreementsProvider::PATH_ENABLED, ScopeInterface::SCOPE_STORE);
$agreementsList = $this->checkoutAgreementsRepository->getList();
$agreementConfiguration['isEnabled'] = (bool) ($isAgreementsEnabled && count($agreementsList) > 0);
foreach ($agreementsList as $agreement) {
$agreementConfiguration['agreements'][] = ['content' => $agreement->getIsHtml() ? $agreement->getContent() : nl2br($this->escaper->escapeHtml($agreement->getContent())), 'checkboxText' => $agreement->getCheckboxText(), 'mode' => $agreement->getMode(), 'agreementId' => $agreement->getAgreementId()];
}
return $agreementConfiguration;
}
示例13: process
/**
* {@inheritdoc}
*/
public function process($jsLayout)
{
$form = [];
$agreementsList = $this->checkoutAgreementsRepository->getList();
foreach ($agreementsList as $agreement) {
$name = $agreement->getAgreementId();
$form[$name] = ['component' => 'Magento_Ui/js/form/element/abstract', 'config' => ['customScope' => 'checkoutAgreements', 'customEntry' => 'checkoutAgreements.' . $name, 'template' => 'Magento_CheckoutAgreements/form/element/agreement'], 'agreementConfiguration' => ['content' => $agreement->getIsHtml() ? $agreement->getContent() : nl2br($this->escaper->escapeHtml($agreement->getContent())), 'height' => $agreement->getContentHeight(), 'checkboxText' => $agreement->getCheckboxText()], 'dataScope' => $name, 'provider' => 'checkoutProvider', 'validation' => ['checked' => true], 'customEntry' => null, 'visible' => true];
}
$result['components']['checkout']['children']['steps']['children']['review']['children']['beforePlaceOrder']['children']['checkoutAgreements']['children'] = $form;
return array_merge_recursive($jsLayout, $result);
}
示例14: _prepareNamePrefixSuffixOptions
/**
* Unserialize and clear name prefix or suffix options
*
* @param string $options
* @return array|bool
*/
protected function _prepareNamePrefixSuffixOptions($options)
{
$options = trim($options);
if (empty($options)) {
return false;
}
$result = [];
$options = explode(';', $options);
foreach ($options as $value) {
$value = $this->escaper->escapeHtml(trim($value));
$result[$value] = $value;
}
return $result;
}
示例15: execute
public function execute()
{
$params = $this->getRequest()->getParams();
/** @var \Magento\Checkout\Model\Cart $cart */
$cart = $this->cartFactory->create();
$successMessage = '';
$websiteId = $this->storeManager->getStore()->getWebsiteId();
foreach ($params as $key => $product) {
if ($product && is_array($product)) {
$productModel = $this->productFactory->create();
// loadByAttribute() return false if the product was not found. There is no need to check the ID,
// but lets stay on the safe side for the future Magento releases
/** @var \Magento\Catalog\Model\Product $productBySKU */
$productBySKU = $productModel->loadByAttribute('sku', $product['sku']);
if (!$productBySKU || !($productId = $productBySKU->getId())) {
continue;
}
$stockItem = $this->stockItemApiFactory->create();
/** @var \Magento\CatalogInventory\Model\ResourceModel\Stock\Item $stockItemResource */
$stockItemResource = $this->stockItemApiResourceFactory->create();
$stockItemResource->loadByProductId($stockItem, $productId, $websiteId);
$qty = $stockItem->getQty();
try {
if (!$cart->getQuote()->hasProductId($productId) && is_numeric($product['qty']) && $qty > $product['qty']) {
$cart->addProduct($productBySKU, (int) $product['qty']);
$successMessage .= __('%1 was added to your shopping cart.' . '</br>', $this->escaper->escapeHtml($productBySKU->getName()));
}
unset($params[$key]);
} catch (\Exception $e) {
$this->rejoinerHelper->log($e->getMessage());
}
}
}
if (isset($params['coupon_code'])) {
$cart->getQuote()->setCouponCode($params['coupon_code'])->collectTotals();
}
try {
$cart->getQuote()->save();
$cart->save();
} catch (\Exception $e) {
$this->rejoinerHelper->log($e->getMessage());
}
$this->checkoutSession->setCartWasUpdated(true);
if ($successMessage) {
$this->messageManager->addSuccess($successMessage);
}
$url = $this->_url->getUrl('checkout/cart/', ['updateCart' => true]);
$this->getResponse()->setRedirect($url);
}