MetaModels\Factory::getMetaModel PHP Method

getMetaModel() public method

public getMetaModel ( $metaModelName )
    public function getMetaModel($metaModelName)
    {
        $event = new CreateMetaModelEvent($this, $metaModelName);
        $this->getEventDispatcher()->dispatch($event::NAME, $event);
        $metaModel = $event->getMetaModel();
        if ($metaModel) {
            $attributeFactory = $this->getServiceContainer()->getAttributeFactory();
            foreach ($attributeFactory->createAttributesForMetaModel($metaModel) as $attribute) {
                $metaModel->addAttribute($attribute);
            }
        }
        return $metaModel;
    }

Usage Example

 /**
  * Get all attribute ids of a metamodel.
  *
  * @param \DataContainer $dataContainer The data container driver.
  *
  * @return array
  */
 public function getAttributes($dataContainer)
 {
     $options = array();
     if ($dataContainer->activeRecord) {
         $layer = LayerModel::findByPk($dataContainer->activeRecord->pid);
         if (!$layer) {
             return $options;
         }
         $name = $this->metaModelsFactory->translateIdToMetaModelName($layer->metamodel);
         $metaModel = $this->metaModelsFactory->getMetaModel($name);
         if ($metaModel) {
             foreach ($metaModel->getAttributes() as $attribute) {
                 $options[$attribute->get('id')] = $attribute->getName();
             }
         }
     }
     return $options;
 }
All Usage Examples Of MetaModels\Factory::getMetaModel