DI not working as expected

Why does AES have exactly 10 rounds for a 128-bit key, 12 for 192 bits and 14 for a 256-bit key size?

How could a planet have erratic days?

15% tax on $7.5k earnings. Is that right?

Why is the Sun approximated as a black body at ~ 5800 K?

How much of a Devil Fruit must be consumed to gain the power?

Can you use Vicious Mockery to win an argument or gain favours?

How to get directions in deep space?

Does the reader need to like the PoV character?

What is going on with gets(stdin) on the site coderbyte?

How to draw a matrix with arrows in limited space

Why does Carol not get rid of the Kree symbol on her suit when she changes its colours?

How much theory knowledge is actually used while playing?

It grows, but water kills it

Can I say "fingers" when referring to toes?

Doesn't the system of the Supreme Court oppose justice?

Why is it that I can sometimes guess the next note?

Do we have to expect a queue for the shuttle from Watford Junction to Harry Potter Studio?

Giving feedback to someone without sounding prejudiced

How can ping know if my host is down

Does Doodling or Improvising on the Piano Have Any Benefits?

When were female captains banned from Starfleet?

Does the Linux kernel need a file system to run?

Why can't the Brexit deadlock in the UK parliament be solved with a plurality vote?

Has the laser at Magurele, Romania reached a tenth of the Sun's power?



DI not working as expected














0















I'm trying to get an instance of MagentoCmsApiGetBlockByIdentifier, however I am receiving a value of null.



I notice the CMS module defines a preference for this interface



vendor/magento/module-cms/etc/di.xml:13:
<preference for="MagentoCmsApiGetBlockByIdentifierInterface" type="MagentoCmsModelGetBlockByIdentifier" />


so I believe this is the correct way to go about getting an instance of MagentoCmsApiGetBlockByIdentifier.



Here is my code:



<?php
namespace CompanyModuleBlockProduct;

use
MagentoCatalogBlockProductViewAbstractView,
MagentoStoreModelStoreManagerInterface,
MagentoCmsApiGetBlockByIdentifierInterface as BlockGetter,
MagentoFrameworkViewElementContext as ElementContext;

class MyBlock extends AbstractView
{
private
$_oStoreManager,
$_oBlockGetter;

public function __constructor(
StoreManagerInterface $oStoreManager,
BlockGetter $oBlockGetter,
ElementContext $context,
array $data = []
) {
$this->_oStoreManager = $oStoreManager;
$this->_oBlockGetter = $oBlockGetter;

parent::__construct($context, $data);
}

/**
* Look on the product to see if there is a value in the
* 'dynamic_block' attribute. If it is, use that value to search
* for a static block with that as an identifier. If found, return the
* markup from the static block. Otherwise return the empty string.
*/
public function toHtml()
{
$staticBlockId = trim($this->getProduct()->getData('dynamic_block'));

if($staticBlockId == '') {
return '';
}

try {
$storeId = $this->_storeManager->getStore()->getId();
//----------------------------------------------------------
/// XXX $this->_oBlockGetter is null ...
$staticBlock = $this->_oBlockGetter->execute($staticBlockId, $storeId);
return $staticBlock->getContent();
} catch(Exception $e) {
return '';
}
}
}








share



























    0















    I'm trying to get an instance of MagentoCmsApiGetBlockByIdentifier, however I am receiving a value of null.



    I notice the CMS module defines a preference for this interface



    vendor/magento/module-cms/etc/di.xml:13:
    <preference for="MagentoCmsApiGetBlockByIdentifierInterface" type="MagentoCmsModelGetBlockByIdentifier" />


    so I believe this is the correct way to go about getting an instance of MagentoCmsApiGetBlockByIdentifier.



    Here is my code:



    <?php
    namespace CompanyModuleBlockProduct;

    use
    MagentoCatalogBlockProductViewAbstractView,
    MagentoStoreModelStoreManagerInterface,
    MagentoCmsApiGetBlockByIdentifierInterface as BlockGetter,
    MagentoFrameworkViewElementContext as ElementContext;

    class MyBlock extends AbstractView
    {
    private
    $_oStoreManager,
    $_oBlockGetter;

    public function __constructor(
    StoreManagerInterface $oStoreManager,
    BlockGetter $oBlockGetter,
    ElementContext $context,
    array $data = []
    ) {
    $this->_oStoreManager = $oStoreManager;
    $this->_oBlockGetter = $oBlockGetter;

    parent::__construct($context, $data);
    }

    /**
    * Look on the product to see if there is a value in the
    * 'dynamic_block' attribute. If it is, use that value to search
    * for a static block with that as an identifier. If found, return the
    * markup from the static block. Otherwise return the empty string.
    */
    public function toHtml()
    {
    $staticBlockId = trim($this->getProduct()->getData('dynamic_block'));

    if($staticBlockId == '') {
    return '';
    }

    try {
    $storeId = $this->_storeManager->getStore()->getId();
    //----------------------------------------------------------
    /// XXX $this->_oBlockGetter is null ...
    $staticBlock = $this->_oBlockGetter->execute($staticBlockId, $storeId);
    return $staticBlock->getContent();
    } catch(Exception $e) {
    return '';
    }
    }
    }








    share

























      0












      0








      0








      I'm trying to get an instance of MagentoCmsApiGetBlockByIdentifier, however I am receiving a value of null.



      I notice the CMS module defines a preference for this interface



      vendor/magento/module-cms/etc/di.xml:13:
      <preference for="MagentoCmsApiGetBlockByIdentifierInterface" type="MagentoCmsModelGetBlockByIdentifier" />


      so I believe this is the correct way to go about getting an instance of MagentoCmsApiGetBlockByIdentifier.



      Here is my code:



      <?php
      namespace CompanyModuleBlockProduct;

      use
      MagentoCatalogBlockProductViewAbstractView,
      MagentoStoreModelStoreManagerInterface,
      MagentoCmsApiGetBlockByIdentifierInterface as BlockGetter,
      MagentoFrameworkViewElementContext as ElementContext;

      class MyBlock extends AbstractView
      {
      private
      $_oStoreManager,
      $_oBlockGetter;

      public function __constructor(
      StoreManagerInterface $oStoreManager,
      BlockGetter $oBlockGetter,
      ElementContext $context,
      array $data = []
      ) {
      $this->_oStoreManager = $oStoreManager;
      $this->_oBlockGetter = $oBlockGetter;

      parent::__construct($context, $data);
      }

      /**
      * Look on the product to see if there is a value in the
      * 'dynamic_block' attribute. If it is, use that value to search
      * for a static block with that as an identifier. If found, return the
      * markup from the static block. Otherwise return the empty string.
      */
      public function toHtml()
      {
      $staticBlockId = trim($this->getProduct()->getData('dynamic_block'));

      if($staticBlockId == '') {
      return '';
      }

      try {
      $storeId = $this->_storeManager->getStore()->getId();
      //----------------------------------------------------------
      /// XXX $this->_oBlockGetter is null ...
      $staticBlock = $this->_oBlockGetter->execute($staticBlockId, $storeId);
      return $staticBlock->getContent();
      } catch(Exception $e) {
      return '';
      }
      }
      }








      share














      I'm trying to get an instance of MagentoCmsApiGetBlockByIdentifier, however I am receiving a value of null.



      I notice the CMS module defines a preference for this interface



      vendor/magento/module-cms/etc/di.xml:13:
      <preference for="MagentoCmsApiGetBlockByIdentifierInterface" type="MagentoCmsModelGetBlockByIdentifier" />


      so I believe this is the correct way to go about getting an instance of MagentoCmsApiGetBlockByIdentifier.



      Here is my code:



      <?php
      namespace CompanyModuleBlockProduct;

      use
      MagentoCatalogBlockProductViewAbstractView,
      MagentoStoreModelStoreManagerInterface,
      MagentoCmsApiGetBlockByIdentifierInterface as BlockGetter,
      MagentoFrameworkViewElementContext as ElementContext;

      class MyBlock extends AbstractView
      {
      private
      $_oStoreManager,
      $_oBlockGetter;

      public function __constructor(
      StoreManagerInterface $oStoreManager,
      BlockGetter $oBlockGetter,
      ElementContext $context,
      array $data = []
      ) {
      $this->_oStoreManager = $oStoreManager;
      $this->_oBlockGetter = $oBlockGetter;

      parent::__construct($context, $data);
      }

      /**
      * Look on the product to see if there is a value in the
      * 'dynamic_block' attribute. If it is, use that value to search
      * for a static block with that as an identifier. If found, return the
      * markup from the static block. Otherwise return the empty string.
      */
      public function toHtml()
      {
      $staticBlockId = trim($this->getProduct()->getData('dynamic_block'));

      if($staticBlockId == '') {
      return '';
      }

      try {
      $storeId = $this->_storeManager->getStore()->getId();
      //----------------------------------------------------------
      /// XXX $this->_oBlockGetter is null ...
      $staticBlock = $this->_oBlockGetter->execute($staticBlockId, $storeId);
      return $staticBlock->getContent();
      } catch(Exception $e) {
      return '';
      }
      }
      }






      dependency-injection





      share












      share










      share



      share










      asked 4 mins ago









      quickshiftinquickshiftin

      951925




      951925






















          0






          active

          oldest

          votes











          Your Answer








          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "479"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: false,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f266896%2fdi-not-working-as-expected%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          0






          active

          oldest

          votes








          0






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes
















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Magento Stack Exchange!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f266896%2fdi-not-working-as-expected%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          “%fieldName is a required field.”, in Magento2 REST API Call for GET Method Type The Next...

          How to change City field to a dropdown in Checkout step Magento 2Magento 2 : How to change UI field(s)...

          變成蝙蝠會怎樣? 參考資料 外部連結 导航菜单Thomas Nagel, "What is it like to be a...