Add arguments in CMS Block

The project is using the Bluefoot plugin to add the block in cms_index_home. I created a static block in Magento Admin with the follow content:

{{block class="Webjump\ProductsRegulars\Block\Recommendation\Lists" name="product-recommendation" template="recommendation/list.phtml}} 

But in my cms_index_home.xml I have some arguments essentials to block.

<arguments>     <argument name="jsLayout" xsi:type="array">         <item name="components" xsi:type="array">             <item name="recommendation-list" xsi:type="array">                 <item name="component" xsi:type="string">ProductsRegulars/js/view/recommendation/list</item>                 <item name="config" xsi:type="array">                     <item name="template" xsi:type="string">ProductsRegulars/recommendation/list</item>                 </item>                  <item name="children" xsi:type="array">                     <item name="messages" xsi:type="array">                         <item name="sortOrder" xsi:type="string">0</item>                         <item name="component" xsi:type="string">Magento_Ui/js/view/messages</item>                         <item name="displayArea" xsi:type="string">messages</item>                     </item>                 </item>             </item>         </item>     </argument> </arguments> 

When I run the page, occur the following error:

Uncaught SyntaxError: Unexpected token u in JSON at position 0 

I believe that this error occurs because of the Magento not found the arguments. Can anyone help me?

Thanks.

Using functional interface arguments in methods of services injected via Spring

Here is the working code for my Spring service:

@Service public class UploadService {      @Inject     @Qualifier("session")     Session session;      @Inject     AsyncImageConvertService asyncImageConvertService;      @Value("$  {aws.bucket-name}")     String awsBucketName;      @Inject     AmazonS3 amazonS3;      @Inject     ImageMapper imageMapper;      @Transactional(isolation = Isolation.READ_COMMITTED, propagation = Propagation.REQUIRED)     public void uploadImage(Image image, String url, Runnable fnSaveObject) {         File file = new File(System.getProperty("java.io.tmpdir"), image.getUrl());          image.setUrl(url);         image.setCreator(session.getUser());         PutObjectRequest request = new PutObjectRequest(awsBucketName, image.getUrl(), file);         request.setCannedAcl(CannedAccessControlList.PublicRead);         amazonS3.putObject(request);          TransactionSynchronizationManager.registerSynchronization(new TransactionSynchronizationAdapter() {             public void afterCommit() {                 asyncImageConvertService.processImage(image.getId(), file);             }         });          imageMapper.insert(image);         fnSaveObject.run();     } } 

It is called from the following code:

uploadService.uploadImage(                 profileImage,                 "/user/" + user.getId() + "/" + profileImage.getUrl(),                 () -> userMapper.insertImage(user, profileImage) ); 

The Runnable functional interface will run in transaction and invoke async service method after transaction committed.

*Mapper is injected instance also, via spring-mybatis.

This code looks like it’s working well, but I’m afraid it’s not safe.

Is it safe to use functional interface arguments in methods of services injected via Spring?

Max function with variable number of arguments

I find it irritating that in standard c++ I can’t do std::max(a, b) = x when it’s possible and that it can’t handle more than 2 arguments. For the second concern I found this: https://www.youtube.com/watch?v=z_fnMdzfWAQ&t=266s and it looks interesting but the usage of pointers confuses me because I don’t understand why they are needed here. Since I want to learn more about c++ I wanted to try to create my own version of std::max while making use of the latest c++ features that I know of.

First I want to make use of concepts to let the user know when the types of arguments are invalid at compilation time:

namespace std1 {  // Helper concept for static_assert template<typename> concept False = false;  template<typename T> concept Boolean = std::is_same_v<T, bool>;  template<typename T> concept TypeLessThanComparable = requires(T a, T b) {     { a < b } -> Boolean; };  template<typename T> concept TypeLessThanEqComparable = requires(T a, T b) {     { a <= b } -> Boolean; };  template<typename T> concept TypeGreaterThanComparable = requires(T a, T b) {     { a > b } -> Boolean; };  template<typename T> concept TypeGreaterThanEqComparable = requires(T a, T b) {     { a >= b } -> Boolean; }; 

These are the functions themselves:

template<typename T> constexpr decltype(auto) max(T&& a) noexcept {     return std::forward<T>(a); }  template<typename T> constexpr decltype(auto) max(T&& a, T&& b) noexcept {     if constexpr(TypeLessThanComparable<T>) {         return a < b ? std::forward<T>(b) : std::forward<T>(a);     }     else if constexpr(TypeLessThanEqComparable<T>) {         return a <= b ? std::forward<T>(b) : std::forward<T>(a);     }     else if constexpr(TypeGreaterThanComparable<T>){         return a > b ? std::forward<T>(a) : std::forward<T>(b);     }     else if constexpr(TypeGreaterThanEqComparable<T>) {         return a >= b ? std::forward<T>(a) : std::forward<T>(b);     }     else {         // if I just put false in static_assert it gives a compilation error no matter what         static_assert(False<void>, "You called max with invalid arguments, cannot find comparison operators for their type");     } }  template<typename T, typename...Ts> constexpr decltype(auto) max(T&& a, T&& b, T&& c, Ts&&...d) noexcept {     return max(a, max(b, max(c, d...))); }  } // namespace std1 

And some tests:

 struct A{};  struct B {     bool operator<(B const&) const noexcept = delete;     bool operator<=(B const&) const noexcept = delete;     bool operator>(B const&) const noexcept = delete;     bool operator>=(B const&) const noexcept; };  int main() {     static_assert(std1::max(1, 2) == 2);      int a = 1;     int b = 5;     int c = 3;     int d = 2;      assert(std1::max(a, b, c, d) == b);      std1::max(b, c, d) = 4;      assert(b == 4);      // This gives a compilation error because the static assertion failed     // (void)std1::max(A{}, A{});      // This works     std1::max(B{}, B{}, B{}, B{}, B{}); } 

I want to know if the code is well written and could replace std::max in c++20, maybe it has bugs that I’m not aware of since I am inexperienced in c++. You could also check the compiler explorer link: https://godbolt.org/z/5urgqR.

Changing the arguments of a specific injectable dependency Magento 2.3

I am trying to change the arguments of a specific injectable dependency. The class in question is: \Magento\Customer\Block\Adminhtml\Edit\Tab\View\PersonalInfo

The construct of this class looks like:

public function __construct(     \Magento\Backend\Block\Template\Context $  context,     AccountManagementInterface $  accountManagement,     \Magento\Customer\Api\GroupRepositoryInterface $  groupRepository,     \Magento\Customer\Api\Data\CustomerInterfaceFactory $  customerDataFactory,     \Magento\Customer\Helper\Address $  addressHelper,     \Magento\Framework\Stdlib\DateTime $  dateTime,     \Magento\Framework\Registry $  registry,     Mapper $  addressMapper,     \Magento\Framework\Api\DataObjectHelper $  dataObjectHelper,     \Magento\Customer\Model\Logger $  customerLogger,     array $  data = [] ) {     $  this->coreRegistry = $  registry;     $  this->accountManagement = $  accountManagement;     $  this->groupRepository = $  groupRepository;     $  this->customerDataFactory = $  customerDataFactory;     $  this->addressHelper = $  addressHelper;     $  this->dateTime = $  dateTime;     $  this->addressMapper = $  addressMapper;     $  this->dataObjectHelper = $  dataObjectHelper;     $  this->customerLogger = $  customerLogger;      parent::__construct($  context, $  data); } 

I want to include 3 further classes without the requirement of copying the constructor in my class therefore in my module’s di.xml I have:

<type name="\Magento\Customer\Block\Adminhtml\Edit\Tab\View\PersonalInfo">     <arguments>         <argument name="data" xsi:type="array">             <item name="pricingHelper" xsi:type="object">Magento\Framework\Pricing\Helper\Data</item>             <item name="myHelper" xsi:type="object">Vendor\Module\Helper\helper</item>             <item name="myCollectionFactory" xsi:type="object">Vendor\Module\Model\ResourceModel\CollectionFactory</item>         </argument>     </arguments> </type> 

Then my class looks like this:

class myClass extends \Magento\Customer\Block\Adminhtml\Edit\Tab\View\PersonalInfo {  public function myFunction() {      $  collection = $  this->myCollectionFactory->create();  }  } 

However, it’s not working and I get the error of

Fatal error: Uncaught Error: Call to a member function create() 

What am I doing wrong?

How can I see exactly what arguments are being passed through a filter so that I may modify them?

I’m having a great deal of trouble phrasing this.

If I were to use the filter

views_edit-page 

How can I see what exactly is being passed through the filter so that I may edit them? Normally I would var_dump something similar to this, to get a breakdown of it’s contents, but due to it being a filter, this does not seem to work.

For example

add_filter('views_edit-page','addFilter');  function addFilter($  views) {   var_dump($  views);   die(); } 

Is what I’d like to do, so that I may see exactly what $ views consists of, in order to edit them. However, this does not work, what is a method I can use in order to see the content of $ views?

How do I pass arguments from one script to other script ,when variables created or dynamical

Scenario Trying to get:- 1)I have a Jenkins job which calls a script followed by some variables
ex:- bash ./Firstscript.sh var par car

  • var value could be 123″ “456” “789 Total 3 values in **var** separated by a space
  • par value could be 234″ “567 there are total 2 values in **par** separated by a space
  • car value could be 345″ “678 there are total 2 values in **car** separated by a space

The jenkins calls ./Firstscript.sh file and passes the values individually, since the shell treats any space as an another variable.so the values passed to ./Firstscript.sh are now


i)v1={1} , v2={2},v3={3} ,w1={4} ,w2={5} ,x1={6} ,x2={7} these are how the values are passing from the first job to the ./Firstscript.sh


ii)Now the./Firstscript.sh which has these 7 values will call another script using
./Secondscript.sh v1 v2 v3 w1 w2 x1 x2

My question is that what if the variables var has only 2 values , car has 3 values and variable par has 5 values. how to pass those values to ./Secondscript.sh dynamically like using **for** loop , **if** , **while** or any other way of achieving it .

I have been trying to get this but due to lack of complete knowledge in linux/shell I am unable to get to the consensus. I can explain any doubts regarding this scenario, any suggestions would be helpful.

Which is the best style for readability in methods with a lot of arguments? [on hold]

I want to discuss what is the best way to write a function with multiple parameters. Inline, split into groups, in column, indented, etc. I found a lot of people do in different ways. What do you prefer and why?

1

public void Play(Type arg0, Type arg1, Type arg2, Type arg3, Type arg4, Type arg5, Type arg6) { } 

2

public void Play(Type arg0, Type arg1,                 Type arg2, Type arg3,                 Type arg4, Type arg5,                 Type arg6) { } 

3

public void Play(Type arg0, Type arg1,                     Type arg2, Type arg3,                     Type arg4, Type arg5,                     Type arg6) { } 

4

public void Play(Type arg0, Type arg1,                     Type arg2, Type arg3,                     Type arg4, Type arg5,                     Type arg6) { } 

5

public void Play(Type arg0,                 Type arg1,                 Type arg2,                 Type arg3,                 Type arg4,                 Type arg5,                 Type arg6) { } 

6

public void Play(Type arg0,                     Type arg1,                     Type arg2,                     Type arg3,                     Type arg4,                     Type arg5,                     Type arg6) { } 

Execute a view in code and pass multiple arguments to an exposed filter?

I am executing a View in code of a paragraph preprocess to allow dynamic listings. The user selects which content types they would like to show, and the View should return nodes of those types with the same taxonomy selected. The idea is they can add multiple paragraphs with different configuration, leveraging the same View just with different arguments.

In this view, Content Type is an exposed filter, set to allow multiple. Here is the code in the preprocess_paragraph hook:

$  types = $  paragraph->field_related_content_types->getValue(); $  content_types = [];  foreach ($  types as $  type) {   $  content_types[] = $  type['target_id']; }  $  view = Views::getView('related_content'); $  view->setDisplay('related_content_display'); $  view->setArguments(['type' => $  content_types]); $  view->setExposedInput(['type' => $  content_types]); $  view->preExecute(); $  view->execute();  if (count($  view->result)) {   $  variables['results'] = $  view->buildRenderable('related_content_display', ['type' => $  content_types]); } 

‘type’ is the filter name in the View. If I change it to only allow one value and pass it as a string, it works. So it seems like a syntax issue, but I cannot figure it out.

The method seems to indicate that this is possible:

  /**    * Sets the arguments for the view.    *    * @param array $  args    *   The arguments passed to the view.    */   public function setArguments(array $  args) {     // The array keys of the arguments will be incorrect if set by     // views_embed_view() or \Drupal\views\ViewExecutable:preview().     $  this->args = array_values($  args);   } 

Looking to shorten method of parsing arguments in BASH

I have here a working method of parsing input arguments however it seems redundant. I would like to shorten this code so it doesn’t appear so repetitive.

tool.sh <file-to-use>  tool.sh <file-to-use> -o <output-file-name>   # If arguments are set and equals "-o" then set APP_NAME if [[ -n $  3 ]] && [[ $  2 = "-o" ]]; then      APP_NAME=$  3  # If argument is set and equals anything besides "-o" throw error and show help menu elif [[ -n $  2 ]] && [[ $  2 != "-o" ]]; then     echo "ERROR: Synatx error."     bash $  0 -h      exit  # If "-o" is set but they did not give a output name throw error and display help menu elif [[ -z $  3 ]] && [[ $  2 = "-o" ]]; then     echo "ERROR: Did not specify output file name."     bash $  0 -h      exit   fi 

Possible to use Variables in Batch file to call an EXE with those variables as command-line arguments? How?

Possible to use Variables in Batch file to call an EXE with those variables as command-line arguments? How?

I read that we can SET various kind of variables in a Batch file.

Can they be used as values to pass as Arguments to an EXE being called/ invoked within that Batch file?