public static function TagView::formatSize in Doubleclick for Publishers (DFP) 8
Formats a size or sizes for javascript.
Parameters
string $size: A size to format. Multiple sizes delimited by comma. Example: '300x600,300x250,fluid'.
Return value
string A string representing sizes that can be used in javascript. Example: "[[300,600],[300,250],'fluid']".
3 calls to TagView::formatSize()
- TagView::getBreakpoints in src/
View/ TagView.php - Gets the breakpoints.
- TagView::getSize in src/
View/ TagView.php - Gets the ad size or sizes.
- TagViewTest::testFormatSize in tests/
src/ Unit/ View/ TagViewTest.php - @covers ::formatSize @dataProvider formatSizeProvider
File
- src/
View/ TagView.php, line 327 - Contains \Drupal\dfp\View\TagView.
Class
- TagView
- A value object to combine a DFP tag with global settings for display.
Namespace
Drupal\dfp\ViewCode
public static function formatSize($size) {
$formatted_sizes = [];
$sizes = explode(',', $size);
foreach ($sizes as $size) {
if ($size == '<none>') {
// If the ad sizes string contains the special keyword "<none>," use an
// empty size list in order to suppress slot display.
$formatted_sizes[] = '[]';
}
elseif (trim($size) == 'fluid') {
// If the ad sizes string contains the special keyword "fluid," use the
// Google NamedSize ['fluid']. See DFP documentation at this link
// https://developers.google.com/doubleclick-gpt/reference?rd=1#type-definitions
// Note that both 'fluid' and ['fluid'] are acceptable forms to declare a slot size as fluid.
$formatted_sizes[] = "'" . trim($size) . "'";
}
else {
$formatted_size = explode('x', trim($size));
$formatted_sizes[] = '[' . implode(', ', $formatted_size) . ']';
}
}
return count($formatted_sizes) == 1 ? $formatted_sizes[0] : '[' . implode(', ', $formatted_sizes) . ']';
}