我正在获取带有视图的产品对象。如何获取其类型?
$view = Views::getView('get_all_products');
$view->execute();
foreach ($view->result as $row) { // products
$product = $row->_entity;
$product = \Drupal::service('entity.repository')->getTranslationFromContext($product); // Translating it
$productType = $product-> ????
...
答案 0 :(得分:2)
我认为这是更好的解决方案:
%IntName%
答案 1 :(得分:0)
我发现一种疯狂的方式是:
$productType = $product->get("type")[0]->get("target_id")->getValue();
有人有更好的解决方案吗?