Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions
Placeholder Class Reference
Inheritance diagram for Placeholder:
LocalInterface AssetInterface

Public Member Functions

 __construct (ContextInterface $context, ScopeConfigInterface $scopeConfig, Repository $assetRepo, $type)
 
 getUrl ()
 
 getContentType ()
 
 getPath ()
 
 getSourceFile ()
 
 getSourceContentType ()
 
 getContent ()
 
 getFilePath ()
 
 getContext ()
 
 getModule ()
 

Detailed Description

A locally available image placeholder file asset that can be referred with a file type

Definition at line 18 of file Placeholder.php.

Constructor & Destructor Documentation

◆ __construct()

__construct ( ContextInterface  $context,
ScopeConfigInterface  $scopeConfig,
Repository  $assetRepo,
  $type 
)

Placeholder constructor.

Parameters
ContextInterface$context
ScopeConfigInterface$scopeConfig
Repository$assetRepo
string$type

Definition at line 64 of file Placeholder.php.

69  {
70  $this->context = $context;
71  $this->scopeConfig = $scopeConfig;
72  $this->assetRepo = $assetRepo;
73  $this->type = $type;
74  }

Member Function Documentation

◆ getContent()

getContent ( )

{Get content of a local asset

Returns
string
}

Implements LocalInterface.

Definition at line 142 of file Placeholder.php.

143  {
144  return null;
145  }

◆ getContentType()

getContentType ( )

{Retrieve type of contents

Returns
string
}

Implements AssetInterface.

Definition at line 93 of file Placeholder.php.

94  {
95  return $this->contentType;
96  }

◆ getContext()

getContext ( )

{Get context of the asset that contains data necessary to build an absolute path or URL to the file

Returns
ContextInterface
}

Returns
ContextInterface

Implements LocalInterface.

Definition at line 169 of file Placeholder.php.

170  {
171  return $this->context;
172  }

◆ getFilePath()

getFilePath ( )

{Get an invariant relative path to file

Returns
string
}

Implements LocalInterface.

Definition at line 150 of file Placeholder.php.

151  {
152  if ($this->filePath !== null) {
153  return $this->filePath;
154  }
155  // check if placeholder defined in config
156  $isConfigPlaceholder = $this->scopeConfig->getValue(
157  "catalog/placeholder/{$this->type}_placeholder",
158  \Magento\Store\Model\ScopeInterface::SCOPE_STORE
159  );
160  $this->filePath = $isConfigPlaceholder;
161 
162  return $this->filePath;
163  }

◆ getModule()

getModule ( )

{Get the module context of file path

Returns
string
}

Implements LocalInterface.

Definition at line 177 of file Placeholder.php.

178  {
179  return 'placeholder';
180  }

◆ getPath()

getPath ( )

{Get a relative "context" path to the asset fileThis path includes both invariant and context part that can serve as an identifier of the file in current context

Returns
string
}

Implements LocalInterface.

Definition at line 101 of file Placeholder.php.

102  {
103  if ($this->getFilePath() !== null) {
104  $result = $this->getContext()->getPath()
105  . DIRECTORY_SEPARATOR . $this->getModule()
106  . DIRECTORY_SEPARATOR . $this->getFilePath();
107  } else {
108  $defaultPlaceholder = $this->assetRepo->createAsset(
109  "Magento_Catalog::images/product/placeholder/{$this->type}.jpg"
110  );
111  try {
112  $result = $defaultPlaceholder->getSourceFile();
113  } catch (NotFoundException $e) {
114  $result = null;
115  }
116  }
117 
118  return $result;
119  }

◆ getSourceContentType()

getSourceContentType ( )

Get source content type

Returns
string

Implements AssetInterface.

Definition at line 134 of file Placeholder.php.

135  {
136  return $this->contentType;
137  }

◆ getSourceFile()

getSourceFile ( )

{Get original source file where the asset contents can be read fromReturns absolute path to file in local file system

Returns
string
}

Implements LocalInterface.

Definition at line 124 of file Placeholder.php.

125  {
126  return $this->getPath();
127  }

◆ getUrl()

getUrl ( )

{Retrieve URL pointing to a resource

Returns
string
}

Implements AssetInterface.

Definition at line 79 of file Placeholder.php.

80  {
81  if ($this->getFilePath() !== null) {
82  $result = $this->context->getBaseUrl() . '/' . $this->getModule() . '/' . $this->getFilePath();
83  } else {
84  $result = $this->assetRepo->getUrl("Magento_Catalog::images/product/placeholder/{$this->type}.jpg");
85  }
86 
87  return $result;
88  }

The documentation for this class was generated from the following file: